0% found this document useful (0 votes)
7 views3 pages

Arduino Program

Iot programming

Uploaded by

poojagaygaye3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Arduino Program

Iot programming

Uploaded by

poojagaygaye3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1) we will add two numbers.

1. void setup()
2. {
3. Serial.begin(9600);
4. }
5. void loop() {
6. int a = 5; // initialization of values to the variables a and b
7. int b = 4;
8. int c;
9. c = myAddfunction(a, b); // c will now contains the value 9
10. Serial.println(c); // to print the resulted value
11. delay(1000); // time delay of 1 second or 1000 milliseconds
12. }
13. int myAddfunction(int i, int j)
14. {
15. int sum;
16. sum = i + j;
17. return sum;
18. }

2)Local Variables
1. void setup()
2. {
3. Serial.begin(9600);
4. }
5. void loop()
6. {
7. int x = 3;
8. int b = 4;
9. int sum = 0;
10. sum = x + b;
11. Serial.println(sum);
12. }

3)Printing the sum of all elements


1. const int sizeOFarray = 5; // constant variable indicating size of array
2. int b[sizeOFarray] = {10, 20, 30, 40, 50}; // five values initialized to five elements of an array
3. int sum = 0;
4.
5. void setup ()
6. {
7. Serial.begin(9600);
8. }
9. void loop ()
10. {
11. // sum of array b
12. for ( int i = 0; i < sizeOFarray; i++ )
13. sum += b[ i ]; // here, sum = sum + b[i]
14. Serial.print('Sum of total elements of an array:') ;
15. Serial.print(sum) ; // It will print the sum of all elements of an array
16. }
Output
Sum of total elements of an array: 150

4)Fined Large no
1. int a = 6; // initiaization of values to variables a and b
2. int b = 4;
3. void setup()
4. {
5. Serial.begin(9600);
6. }
7. void loop()
8. {
9. if (a > b )
10. {
11. Serial.println( " a is greater than b ");
12. }
13. if (b > a )
14. {
15. Serial.println( " b is greater than a ");
16. }
17. }

5)Print 1 to 10 no
1. int i;
2. void setup ( )
3. {
4. Serial.begin(9600);
5. for ( i = 1 ; i < =10 ; i ++ )
6. {
7. Serial.println( i);
8. }
9. }
10. void loop ( ) {
11. }

6)Return Char of given Position


1. void setup()
2. {
3. Serial.begin(9600);
4. String thisString = "Welcome to Arduino";
5. Serial.println(thisString.charAt(8));
6. }
7. void loop()
8. {
9. }

7)Concatinate two string


1. void setup()
2. {
3. Serial.begin(9600);
4. String thisString = "Welcome to Arduino";
5.
6. thisString.concat("String Object");
7.
8. Serial.println(thisString);
9. }
10. void loop()
11. {
12. }

You might also like