ARDUINO TRAINING - Day 1
ARDUINO TRAINING - Day 1
ARDUINO TRAINING - Day 1
Computer Programming -- is often called coding. It is the process of writing, testing, debugging and maintaining the source code of computer programs.
Computer Program is known as software program. It is a structured collection of instructions to the computer.
It is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of a source code editor, a compiler and/or interpreter, build automation tools, and usually a debugger.
This window contains the interface 'Projects' which will in the following text be referred to as the project view. This view show all the projects opened in CodeBlocks at a certain time. The 'Symbols' tab of the Management window shows symbols and variables.
It is a computer program that translates text written in a computer language (the source language) into another computer language (the target language)
It
Head Body
These commands tells the compiler to do preprocessing before doing actual compilation.
#include <stdio.h> int main() { double C, F; /*read in value for C*/ printf(Enter Celsius temp: ); scanf(%lf,&C); /* Calculate F */ F = (9/5) * C + 32; /* Display the value of F */ printf(The equivalent Fahrenheit is %lf \n, F); return 0; }
#include <stdio.h> int main() { double C, F; /*read in value for C*/ printf(Enter Celsius temp: ); scanf(%lf,&C); /* Calculate F */ F = (9/5) * C + 32; /* Display the value of F */ printf(The equivalent Fahrenheit is %lf \n, F); return 0; }
are used to hold numbers, strings and complex data for manipulation
#include <stdio.h> int main() { double C, F; /*read in value for C*/ printf(Enter Celsius temp: ); scanf(%lf,&C); /* Calculate F */ F = (9/5) * C + 32; /* Display the value of F */ printf(The equivalent Fahrenheit is %lf \n, F); return 0; }
Expressions combine variables and constants to create new values. Statements are expressions, assignments, function calls, or control flow statements which make up C programs.
#include <stdio.h> int main() { double C, F; /*read in value for C*/ printf(Enter Celsius temp: ); scanf(%lf,&C); /* Calculate F */ F = (9/5) * C + 32; /* Display the value of F */ printf(The equivalent Fahrenheit is %lf \n, F); return 0; }
Write one statement per line. Put spaces before and after each arithmetic operator, just like you put spaces between words when you write.
/* Poor programming practice */ biggest=-l;first=0;count=57;init_key_words(); If (debug)open_log_files();table_size=parse_size+lexsize; /* Better programming practice*/ biggest=-l; first=0; count=57; init_key_words(); if(debug) open_log_files(); table_size=parse_size + lex_size;
/* Good practice */ delta_value = (old_value - new_value); delta_total = (total_old - total_new); gain = delta_value / delta_total * 100.0;
Naming
Variables
Example
Variables
Variable names in C
May only consist of letters, digits, and underscores May be as long as you like, but only the first 31 characters are significant May not begin with a number May not be a C reserved word (keyword)
int register return short sizeof struct switch typedef unsigned volatile
long
signed static
Begin variable names with lowercase letters Use meaningful identifiers Separate words within identifiers with underscores or mixed upper and lower case.
Examples: surfaceArea surface_Area surface_area
Be consistent!
Use all uppercase for symbolic constants (used in #define preprocessor directives). Examples:
C is case sensitive
Example: area Area AREA ArEa
Integers Floating
int, long int, short int, unsigned int float, double char
Characters
Description Single character Integer or decimal Number Floating point number or real Double Floating point number with 2 decimal places
3.10
Examples:
int length = 7 ; float diameter = 5.9 ; char initial = A ; double cash = 1058635.5285
a comment is always a good idea Example: int height = 4; // rectangle height int width = 6 ; // rectangle width int area ; // rectangle area
Place each variable declaration on its own line with a descriptive comment. Example : float inches ; // number of inches deep
Place a comment before each logical chunk of code describing what it does.
/* Get the depth in fathoms from the user*/ printf(Enter the depth in fathoms: );
Example :
Do
not place a comment on the same line as code (with the exception of variable declarations).
blank lines to enhance readability.
Use
Use
#include <stdio.h> int main( ) { float inches ; float feet ; float fathoms ;
Assignment
#include <stdio.h> int main( ) { int inches, feet, fathoms ; fathoms = 7 ; feet = 6 * fathoms ; inches = 12 * feet ;
. . .
F Execute S_2
Write a program that reads in an integer and then display whether the number is positive or negative.
Write a program that reads weight in pounds and output the weight in kilograms. Moreover, if the weight in kilogram exceeds 60 kilos, then display the message GO ON DIET, else YOU ARE IN GOOD SHAPE
Used to check the value of a certain item that may have more than one outcome
Basic Syntax:
if (conditional expr) statement_1; else if (conditional expr) statement_2; else if (conditional expr) statement_3; else if (conditional expr) statement_n;
Write a program that reads in an integer and then display whether the number is positive or negative or neither when the user enters 0.
Write a program that reads the students average grade in Programming and then output his grade standing according to the following scheme
GRADE STANDING F C B A
AVERAGE GRADE Below 75 At least 75 but below 85 At least 85 but below 95 At least 95
Elementary Arithmetic Operations 1. Addition 2. Subtraction 3. Multiplication 4. Division Input your choice (1-4): The user then asked to type two integers and the correct answer. Your program should also inform the user whether the answer is correct or not.
Write a program to display a menu system for an elementary arithmetic operation and then ask the user to select the operation he or she wants
Basic Syntax:
switch (expression) { case constant 1; statement 1; statement 2; statement n; break; case constant 2;
statement 1; statement 2; statement n; break;
case constant n;
statement 1; statement 2; statement n; break;
default: statement; }
Create a Number Base converter program that allows the user to select from the four options given
NUMBER BASE CONVERTER 1. Decimal to Hexadecimal 2. Hexadecimal to Decimal 3. Decimal to Octal 4. Octal to Decimal Input your choice (1-4):
Write a program that reads the students average grade in Programming and then output his grade standing according to the following scheme
GRADE STANDING F C B A
AVERAGE GRADE Below 75 At least 75 but below 85 At least 85 but below 95 At least 95
The general from of while initialize loop counter; while (test loop counter using a condition) { statement_1; statement_2; increment loop counter; }
Write a program that reads in an integer and then calculate the sum of the positive integers from 1 to N.
Write a program that reads in an integer and then count the number of positive and negative numbers
The The general from of dowhile conditional expression is do { placed at the statement_1; end of the statement_2; loop statement_2; } while (conditional expression);
Write a program that reads in 10 positive integers and then calculate its sum.
Sample Output
5*1=5 5*2=10 5*3=15 5*10=50
Modify the sample problem so that it will ask the user for the number to multiply and the number of terms.