At this stage I have only just received the Lilypad Arduino so will not be using it for the minor.
The major projects code will have a much stronger structure. The code for this is very basic but it represents how the major project will function.
Code:
const int leftButton = 7;
const int rightButton = 8;
const int leftLED = 11;
const int rightLED = 12;
boolean leftBool;
boolean rightBool;
int x;
int buttonStateL = 0; // variable for reading the pushbutton status
int buttonStateR = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(leftLED, OUTPUT);
pinMode(rightLED, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(rightButton, INPUT);
pinMode(leftButton, INPUT);
leftBool = false;
rightBool = false;
}
void loop(){
// read the state of the pushbutton value:
//right
buttonStateR = digitalRead(rightButton);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonStateR == HIGH) {
rightBool = true;
}
if (rightBool == true)
{
// turn LED on:
for (x=0;x less than 10;x++)
{
digitalWrite(rightLED, HIGH);
delay(500);
digitalWrite(rightLED, LOW);
delay(500);
}
rightBool = false;
}
//left buttonStateL
buttonStateL = digitalRead(leftButton);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonStateL == HIGH)
{
leftBool = true;
}
if (leftBool == true)
{
// turn LED on:
for (x=0;x less than 10;x++)
{
digitalWrite(leftLED, HIGH);
delay(500);
digitalWrite(leftLED, LOW);
delay(500);
}
leftBool = false;
}
}
Fritzing Diagram:
Note: from first attempt.
Photos:
Photos:
Video:
No comments:
Post a Comment