I have picked up on a number of small programming tasks that have been set.
The first of these is to turn a light on when a button is pressed.
// turn on led when button is pressed
#define LED 13 //the pin for the LED
#define BUTTON 7 //the pin for the button
int val = 0; //val will be used to
//store the state of the //input pin
void setup() {
pinMode(LED,OUTPUT);
//set the LED as an output
pinMode(BUTTON, INPUT);
//set the button as an input
}
void loop() {
val = digitalRead(BUTTON);
//read the button and store
//answer check to see if input is high
if (val == HIGH){
digitalWrite(LED, HIGH);
//turn LED on
} else {
digitalWrite(LED, LOW);
}
}
I found this initial program relatively easy; the only problem I have with this one is the double = sign used to make a comparison.
The rest is just terminology.