02 / In class : Language and Operators
- Feb 1, 2016
- 2 min read
Comparion Operators VS Boolean Operators
Language Reference (more info)
Comparison Operators : The system only looks for a yes or no answer ( TRUE (1) & FALSE (2))
IF statement
One condition :
if (someCondition) { // do stuff if the condition is true } else { // do stuff if the condition is false }
Multiple layers of conditions :
if (someCondition) { // do stuff if the condition is true } else if (anotherCondition) { // do stuff only if the first condition is false // and the second condition is true }
** Caution
= (one equal sign) Assignment
== (two equal signs) Equal to
Boolean operators :
&& And
ll Or
For Statement

Variable : When to start
Test : For how long
Increment : How it change overtime
SensorValue++ // mean SensorValue +1
fadeValue+=5 // tell a specific increment
Each pin port capability.
Digital Read : All
Digital Write : All
Analog Read : A0-A5 ( only analyze 0-1023)
Analog Write : 3,5,6,9,10,11 (only analyze 0-255 (Full brightness))
For example :
when we applied "Fade", we used pin no.9 instead of no.13 because pin no.13 can't do analog write.
"AnalogInput"
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
if (sensorValue >=500) {
digitalWrite(ledPin, HIGH);}
// stop the program for <sensorValue> milliseconds:
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}
// Debug //
Problem The light only was on once!
Hypothesis I added the if statement in a wrong position, in the void setup.
Result If statement needed to be added between void loop so that it will active constantly!














Comments