SlideShare a Scribd company logo
1 of 26
Download to read offline
Variables
Variables
Variables
Variable data types
int value = 150 ;
char chr_a = ‘a’ ;
Variable scope
Int X = 0 ; Global variable declaration
Void setup () {
}
Void loop () {
int z = 0 ; Local variable declaration
}
Strings
void loop() {
char my_str[6];
my_str[0] = 'H';
my_str[1] = 'e';
my_str[2] = 'l';
my_str[3] = 'l';
my_str[4] = 'o';
char like[] = "I like coffee and cake";
}
Arrays
type arrayName [ arraySize ] ;
int C[ 12 ]; // C is an array of 12 integers
Control structures
if
if...else
switch...case
do
do...while
for
*jump statements:
continue, goto,
break
Functions
Functions
int pin = 13;
void setup()
{
pinMode(pin, OUTPUT);
}
void loop()
{
dot(); dot(); dot();
dash(); dash(); dash();
dot(); dot(); dot();
delay(3000);
}
void dot()
{
digitalWrite(pin, HIGH);
delay(250);
digitalWrite(pin, LOW);
delay(250);
}
void dash()
{
digitalWrite(pin, HIGH);
delay(1000);
digitalWrite(pin, LOW);
delay(250);
}
Operators
Arithmetic Operators
Comparison Operators
Boolean Operators
Bitwise Operators
Compound Operators
Arithmetic Operators
+ - * / % =
void loop () {
int a = 9, b = 4, c;
c = a + b;
c = a – b;
c = a * b;
c = a / b;
c = a % b;
}
Arithmetic Operators
+ - * / % =
void loop () {
int a = 9, b = 4, c;
c = a + b; //13
c = a – b; //5
c = a * b; //36
c = a / b; //2
c = a % b; //1
}
Comparison Operators
== != < > <= >=
void loop () {
int a = 9, b = 4
if(a == b){}
if(a != b){}
if(a < b){}
if(a > b){}
if(a <= b){}
if(a >= b){}
}
Comparison Operators
== != < > <= >=
void loop () {
int a = 9, b = 4
if(a == b){} // false
if(a != b){} // true
if(a < b){} // false
if(a > b){} // true
if(a <= b){} // false
if(a >= b){} // true
}
Boolean Operators
&& || !
void loop () {
int a = 9, b = 4
if((a > b) && (b < a)){}
if((a == b) || (b < a)){}
if( !(a == b) && (b < a)){}
}
Boolean Operators
&& || !
void loop () {
int a = 9, b = 4
if((a > b) && (b < a)){} // true
if((a == b) || (b < a)){} // true
if( !(a == b) && (b < a)){} // true
}
Bitwise Operators
& | ^ ~ << >>
void loop () {
int a = 10; // 0b00001010
int b = 20; // 0b00010100
int c;
c = a & b ;
c = a | b ;
c = a ^ b ;
c = ~a ;
c = a << 2 ;
c = b >> 2 ;
}
Bitwise Operators
& | ^ ~ << >>
void loop () {
int a = 10; // 0b00001010
int b = 20; // 0b00010100
int c;
c = a & b ; // 0b00000000
c = a | b ; // 0b00011110
c = a ^ b ; // 0b00011110
c = ~a ; // 0b11110101
c = a << 2 ; // 0b00101000
c = b >> 2 ; // 0b00000101
}
Bitwise Operators
++ – += -= *= /= %= |= &=
void loop () {
int a = 10, b = 20
int c = 0;
a++;
a--;
b += a; // b=b+a
b -= a; // b=b-a
}
Bitwise Operators
++ – += -= *= /= %= |= &=
void loop () {
int a = 10, b = 20
int c = 0;
a++; // 11
a--; // 9
b += a; // 30
b -= a; // 10
}
Challenges:
1. Take user input from the keyboard to change the color of an RGB LED.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/SwitchCase2
2. Create an array of 255 distinct values (bonus if the numbers are meaningful in some way).
https://www.arduino.cc/reference/en/language/variables/data-types/array/
3. Tell if a user's input was even or odd.
https://www.tutorialspoint.com/arduino/arduino_arithmetic_operators.htm
4. Take a diameter of a circle from the user and return the circumference as a decimal (e.g. 8.56930).
https://www.arduino.cc/reference/en/language/variables/data-types/float/
5. BONUS: Make code that generates abstract ASCII art/drawings in the serial monitor!!
https://en.wikipedia.org/wiki/ASCII_art
https://manytools.org/hacker-tools/convert-images-to-ascii-art/
6. *BONUS BONUS*: Make a text-based "Choose your own adventure" video game!!
https://en.wikipedia.org/wiki/Colossal_Cave_Adventure
https://en.wikipedia.org/wiki/Choose_Your_Own_Adventure
Challenges:
1. Take user input from the keyboard to change the color of an RGB LED.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/SwitchCase2
void setup() {
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
void loop() {
if(Serial.available() > 0) {
int inByte = Serial.read();
switch (inByte) {
case 'a':
digitalWrite(3, HIGH);
break;
case 'b':
digitalWrite(4, HIGH);
break;
case 'c':
digitalWrite(5, HIGH);
break;
}
}
}
Challenges:
2. Create an array of 255 distinct values (bonus if the numbers are meaningful in some way).
https://www.arduino.cc/reference/en/language/variables/data-types/array/
void setup(){
Serial.begin(9600);
}
void loop(){
delay(100);
int my_array[252];
for (int i = 0; i < 252; i++) {
my_array[i]=i;
delay(100);
Serial.println(my_array[i]);
}
}
OR:
int A[255]; //create an array composed of 255 elements
void setup() {
Serial.begin(9600); //initialize the serial monitor
for( int i = 254; i >= 0; i--){ //initialize a variable "i" which the value decrements until it reaches 0.
A[i] = i; //define an element of the array as "i"
Serial.println(A[i]); //display the array in the serial monitor
}
}
void loop() {
}
Challenges:
3. Tell if a user's input was even or odd.
https://www.tutorialspoint.com/arduino/arduino_arithmetic_operators.htm
int incomingByte = 0; //Create a variable for the data input
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) { //read the sensor
incomingByte = Serial.read();
}
if (incomingByte%2 == 0){ //if the number read is divisible by two
Serial.println ("even"); //it is an even number
}
else { //otherwise
Serial.println ("odd"); //the value remaining means it is an odd number
}
}
Challenges:
4. Take a diameter of a circle from the user and return the circumference as a decimal (e.g. 8.56930).
https://www.arduino.cc/reference/en/language/variables/data-types/float/
float Pi = 3.14; //Create a variable Pi
int d = 0; //Creat a variable "d" as diameter
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0.0) {
d = Serial.read()-48; //convert from ASCII to integer
float c = Pi * (float(d)); //Create "c", Circonference is equal to Pi x diameter
Serial.println(c);
}
}

More Related Content

What's hot

How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in Swift
Giordano Scalzo
 
Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
Giordano Scalzo
 
Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6
fisher.w.y
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
qmmr
 

What's hot (20)

C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
 
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
 
C++ L10-Inheritance
C++ L10-InheritanceC++ L10-Inheritance
C++ L10-Inheritance
 
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
 
Documento de acrobat2
Documento de acrobat2Documento de acrobat2
Documento de acrobat2
 
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
 
C++ game development with oxygine
C++ game development with oxygineC++ game development with oxygine
C++ game development with oxygine
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in Swift
 
Oxygine 2 d objects,events,debug and resources
Oxygine 2 d objects,events,debug and resourcesOxygine 2 d objects,events,debug and resources
Oxygine 2 d objects,events,debug and resources
 
Cocos2d Performance Tips
Cocos2d Performance TipsCocos2d Performance Tips
Cocos2d Performance Tips
 
Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
 
Php radomize
Php radomizePhp radomize
Php radomize
 
Minerva_lib - fuzzing tool
Minerva_lib - fuzzing toolMinerva_lib - fuzzing tool
Minerva_lib - fuzzing tool
 
HailDB: A NoSQL API Direct to InnoDB
HailDB: A NoSQL API Direct to InnoDBHailDB: A NoSQL API Direct to InnoDB
HailDB: A NoSQL API Direct to InnoDB
 
Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6
 
A simple snake game project
A simple snake game projectA simple snake game project
A simple snake game project
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
Myraytracer
MyraytracerMyraytracer
Myraytracer
 

Similar to Arduino coding class

include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
contact32
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
eyelineoptics
 
Arduino sectionprogramming slides
Arduino sectionprogramming slidesArduino sectionprogramming slides
Arduino sectionprogramming slides
Jorge Joens
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
GkhanGirgin3
 

Similar to Arduino coding class (20)

include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th Study
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 
Effective C#
Effective C#Effective C#
Effective C#
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
Arduino sectionprogramming slides
Arduino sectionprogramming slidesArduino sectionprogramming slides
Arduino sectionprogramming slides
 
Arduino section programming slides
Arduino section programming slidesArduino section programming slides
Arduino section programming slides
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
 
Intro to c programming
Intro to c programmingIntro to c programming
Intro to c programming
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
C programming
C programmingC programming
C programming
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Arduino Section Programming - from Sparkfun
Arduino Section Programming - from SparkfunArduino Section Programming - from Sparkfun
Arduino Section Programming - from Sparkfun
 
Tu1
Tu1Tu1
Tu1
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
 
pointers 1
pointers 1pointers 1
pointers 1
 

More from Jonah Marrs (8)

Sensors class
Sensors classSensors class
Sensors class
 
Etapes fab-venti-v2
Etapes fab-venti-v2Etapes fab-venti-v2
Etapes fab-venti-v2
 
Arduino creative coding class part iii
Arduino creative coding class part iiiArduino creative coding class part iii
Arduino creative coding class part iii
 
Assembly class
Assembly classAssembly class
Assembly class
 
Arduino workshop
Arduino workshopArduino workshop
Arduino workshop
 
Shop bot training
Shop bot trainingShop bot training
Shop bot training
 
Microcontroller primer
Microcontroller primerMicrocontroller primer
Microcontroller primer
 
Eagle pcb tutorial
Eagle pcb tutorialEagle pcb tutorial
Eagle pcb tutorial
 

Recently uploaded

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Recently uploaded (20)

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 

Arduino coding class

  • 4. Variable data types int value = 150 ; char chr_a = ‘a’ ;
  • 5. Variable scope Int X = 0 ; Global variable declaration Void setup () { } Void loop () { int z = 0 ; Local variable declaration }
  • 6. Strings void loop() { char my_str[6]; my_str[0] = 'H'; my_str[1] = 'e'; my_str[2] = 'l'; my_str[3] = 'l'; my_str[4] = 'o'; char like[] = "I like coffee and cake"; }
  • 7. Arrays type arrayName [ arraySize ] ; int C[ 12 ]; // C is an array of 12 integers
  • 10. Functions int pin = 13; void setup() { pinMode(pin, OUTPUT); } void loop() { dot(); dot(); dot(); dash(); dash(); dash(); dot(); dot(); dot(); delay(3000); } void dot() { digitalWrite(pin, HIGH); delay(250); digitalWrite(pin, LOW); delay(250); } void dash() { digitalWrite(pin, HIGH); delay(1000); digitalWrite(pin, LOW); delay(250); }
  • 11. Operators Arithmetic Operators Comparison Operators Boolean Operators Bitwise Operators Compound Operators
  • 12. Arithmetic Operators + - * / % = void loop () { int a = 9, b = 4, c; c = a + b; c = a – b; c = a * b; c = a / b; c = a % b; }
  • 13. Arithmetic Operators + - * / % = void loop () { int a = 9, b = 4, c; c = a + b; //13 c = a – b; //5 c = a * b; //36 c = a / b; //2 c = a % b; //1 }
  • 14. Comparison Operators == != < > <= >= void loop () { int a = 9, b = 4 if(a == b){} if(a != b){} if(a < b){} if(a > b){} if(a <= b){} if(a >= b){} }
  • 15. Comparison Operators == != < > <= >= void loop () { int a = 9, b = 4 if(a == b){} // false if(a != b){} // true if(a < b){} // false if(a > b){} // true if(a <= b){} // false if(a >= b){} // true }
  • 16. Boolean Operators && || ! void loop () { int a = 9, b = 4 if((a > b) && (b < a)){} if((a == b) || (b < a)){} if( !(a == b) && (b < a)){} }
  • 17. Boolean Operators && || ! void loop () { int a = 9, b = 4 if((a > b) && (b < a)){} // true if((a == b) || (b < a)){} // true if( !(a == b) && (b < a)){} // true }
  • 18. Bitwise Operators & | ^ ~ << >> void loop () { int a = 10; // 0b00001010 int b = 20; // 0b00010100 int c; c = a & b ; c = a | b ; c = a ^ b ; c = ~a ; c = a << 2 ; c = b >> 2 ; }
  • 19. Bitwise Operators & | ^ ~ << >> void loop () { int a = 10; // 0b00001010 int b = 20; // 0b00010100 int c; c = a & b ; // 0b00000000 c = a | b ; // 0b00011110 c = a ^ b ; // 0b00011110 c = ~a ; // 0b11110101 c = a << 2 ; // 0b00101000 c = b >> 2 ; // 0b00000101 }
  • 20. Bitwise Operators ++ – += -= *= /= %= |= &= void loop () { int a = 10, b = 20 int c = 0; a++; a--; b += a; // b=b+a b -= a; // b=b-a }
  • 21. Bitwise Operators ++ – += -= *= /= %= |= &= void loop () { int a = 10, b = 20 int c = 0; a++; // 11 a--; // 9 b += a; // 30 b -= a; // 10 }
  • 22. Challenges: 1. Take user input from the keyboard to change the color of an RGB LED. https://www.arduino.cc/en/Tutorial/BuiltInExamples/SwitchCase2 2. Create an array of 255 distinct values (bonus if the numbers are meaningful in some way). https://www.arduino.cc/reference/en/language/variables/data-types/array/ 3. Tell if a user's input was even or odd. https://www.tutorialspoint.com/arduino/arduino_arithmetic_operators.htm 4. Take a diameter of a circle from the user and return the circumference as a decimal (e.g. 8.56930). https://www.arduino.cc/reference/en/language/variables/data-types/float/ 5. BONUS: Make code that generates abstract ASCII art/drawings in the serial monitor!! https://en.wikipedia.org/wiki/ASCII_art https://manytools.org/hacker-tools/convert-images-to-ascii-art/ 6. *BONUS BONUS*: Make a text-based "Choose your own adventure" video game!! https://en.wikipedia.org/wiki/Colossal_Cave_Adventure https://en.wikipedia.org/wiki/Choose_Your_Own_Adventure
  • 23. Challenges: 1. Take user input from the keyboard to change the color of an RGB LED. https://www.arduino.cc/en/Tutorial/BuiltInExamples/SwitchCase2 void setup() { Serial.begin(9600); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); } void loop() { if(Serial.available() > 0) { int inByte = Serial.read(); switch (inByte) { case 'a': digitalWrite(3, HIGH); break; case 'b': digitalWrite(4, HIGH); break; case 'c': digitalWrite(5, HIGH); break; } } }
  • 24. Challenges: 2. Create an array of 255 distinct values (bonus if the numbers are meaningful in some way). https://www.arduino.cc/reference/en/language/variables/data-types/array/ void setup(){ Serial.begin(9600); } void loop(){ delay(100); int my_array[252]; for (int i = 0; i < 252; i++) { my_array[i]=i; delay(100); Serial.println(my_array[i]); } } OR: int A[255]; //create an array composed of 255 elements void setup() { Serial.begin(9600); //initialize the serial monitor for( int i = 254; i >= 0; i--){ //initialize a variable "i" which the value decrements until it reaches 0. A[i] = i; //define an element of the array as "i" Serial.println(A[i]); //display the array in the serial monitor } } void loop() { }
  • 25. Challenges: 3. Tell if a user's input was even or odd. https://www.tutorialspoint.com/arduino/arduino_arithmetic_operators.htm int incomingByte = 0; //Create a variable for the data input void setup() { Serial.begin(9600); } void loop() { if (Serial.available() > 0) { //read the sensor incomingByte = Serial.read(); } if (incomingByte%2 == 0){ //if the number read is divisible by two Serial.println ("even"); //it is an even number } else { //otherwise Serial.println ("odd"); //the value remaining means it is an odd number } }
  • 26. Challenges: 4. Take a diameter of a circle from the user and return the circumference as a decimal (e.g. 8.56930). https://www.arduino.cc/reference/en/language/variables/data-types/float/ float Pi = 3.14; //Create a variable Pi int d = 0; //Creat a variable "d" as diameter void setup() { Serial.begin(9600); } void loop() { if (Serial.available() > 0.0) { d = Serial.read()-48; //convert from ASCII to integer float c = Pi * (float(d)); //Create "c", Circonference is equal to Pi x diameter Serial.println(c); } }