IT Section 2
IT Section 2
(Arduino)
Section 2
Previous Section Task
Using 3 LED’s (red, yellow and green) build a traffic light that
• Illuminates the green LED for 5 seconds
• Illuminates the yellow LED for 2 seconds
• Illuminates the red LED for 5 seconds
• repeats the sequence
• Note that after each illumination period the LED is turned off!
Previous Section Task
Comments
Comments
Variables
Value
DECLARING A VARIABLE
int val =
Data Type
5;
Value
Variable Name Assignment
sign
“becomes”
Variable Types
•Global
_________________
•Function-level
Using Variables
int delayTime = 2000; Declare delayTime and
int greenLED = 10; greenLED
void setup() { Variable
pinMode(greenLED, OUTPUT);
}
void loop() {
digitalWrite(greenLED, HIGH);
delay(delayTime);
digitalWrite(greenLED, LOW);Use delayTime
Variable
delay(delayTime);
}
Arithmetic Operations
+ Addition 34 + 1 35
- Subtraction 34 - 1 33
Serial.begin(9600);
}
Using Serial Communication
(Output)
Opens up a Serial
Terminal Window
Writing to the Console
if(true)
{
“perform some
action”
}
Comparison Operations
<Boolean> Description
( ) == ( ) is equal?
( ) != ( ) is not equal?
() > () greater than
( ) >= ( ) greater than or equal
() < () less than
( ) <= ( ) less than or equal
IF Condition example