Hi folks, Im hoping someone here can help me - Im a technology and engineering teacher and we are switching from PBasic STAMP to Arduino and trying to create a workbook for pupils to follow to help them learn how to use it. The only problem is that Im not that skilled at it yet. I've been following Jeremy Blum's on-line tutorials and have found them of great benefit.
In his second tutorial he goes over how to keep an output state on as well as debouncing a switch (code below)
/*
Arduino Tutorials
Episode 2
Switch3 Program (debounced)
Written by: Jeremy Blum
*/
int switchPin = 8;
int ledPin = 13;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;
void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}
boolean debounce(boolean last)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
delay(5);
current = digitalRead(switchPin);
}
return current;
}
void loop()
{
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
ledOn = !ledOn;
}
lastButton = currentButton;
digitalWrite(ledPin, ledOn);
}
my problem is that Im now trying to modify this to create work for my pupils. My idea is that they will design a queueing system for a theme park, in which an employee will push one button and it will show a red stop light, and when ready push another button that will switch this light off, and show green, later press the first button, green goes off and red goes on......you get the point!
Ive modified the inputs and outputs to set them up properly as shown
/*
Queue control System
*/
int greenswitchPin = 2;
int redswitchPin = 4;
int greenledPin = 8;
int redledPin = 13;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;
void setup()
{
pinMode(greenswitchPin, INPUT);
pinMode(redswitchPin, INPUT);
pinMode(greenledPin, OUTPUT);
pinMode(redledPin, OUTPUT);
}
but REALLY confused where to go from here - do I just have to copy the next part of the sketch for red, and then for gree?
can anyone help me please while Ive still got some hair on my head! haha
thanks in advance!!!