Hi,
I have made a circuit like the picture is showing. What I want to achieve is when I touch the button once, the LEDs will turn on. If I touch the button the second time I want the LEDs to go on and off in an interval (mode1). If I touch the button the third time, I want the LEDs to turn on and off in a different interval than the previous. I want to have four different modes (including just having the LEDs on), and with the fifth touch on the button, the LEDs will turn off.
I am very new in programming, but this is how I see before me the sequence of the program:
- Initialize all variables
- Set initial condition
- Tell the micro controller to continuously count how many times the touch button is being pressed.
-
If pressed once, this happens: LEDs on.
-
If pressed twice, LEDs on, interval 1
-
If pressed three times; LEDs on, interval 2
-
If pressed four times; LEDs on, interval 3
-
If pressed five times; LEDs off and the counter is being reset.
This is how my program looks like.
/*
*Blink
*This is a prototype for the Aurora scooter jacket.
*Created 17th of September 2012
*By Janniche Aaroen
*/
int ledPin = 13; // the LED on the Lilypad
int shoulder = 11; // Red LEDs
int back = 10; // Red LEDs
int frontdown = 9; // White LEDs
int fronttop = 3; // White LEDs
int pushbutton = 7; // pushbutton
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = LOW; // current state of the button
int lastButtonState = LOW; // previous state of the button
// The setup() method runs once, when the sketch starts
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // sets the LedPin to be an output
pinMode(shoulder, OUTPUT); // sets the shoulder to be an output
pinMode(back, OUTPUT); // sets the back to be an output
pinMode(frontdown, OUTPUT); // sets the frontdown to be an output
pinMode(fronttop, OUTPUT); // sets the fronttop to be an output
pinMode(pushbutton, INPUT); // sets the button to an input signal
digitalWrite(ledPin, LOW); // sets the ledPin to LOW
digitalWrite(shoulder, LOW); // sets the shoulder pin to LOW
digitalWrite(back, LOW); // sets the back pin to LOW
digitalWrite(frontdown, LOW); // sets the frontdown pin to LOW
digitalWrite(fronttop, LOW); // sets the fronttop pin to LOW
}
void loop(){
{ buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter, DEC);
if(buttonPushCounter == 1);
{
digitalWrite(shoulder, HIGH);
digitalWrite(back, HIGH);
digitalWrite(frontdown, HIGH);
digitalWrite(fronttop, HIGH); }
if(buttonPushCounter == 2);
{ void loop();
{
digitalWrite(shoulder, HIGH);
digitalWrite(back, HIGH);
digitalWrite(frontdown, HIGH);
digitalWrite(fronttop, HIGH);
delay(500); // wait for 0,5 second
digitalWrite(shoulder, LOW);
digitalWrite(back, LOW);
digitalWrite(frontdown, LOW);
digitalWrite(fronttop, LOW);
delay(500); } }
}
}
I have only put in the two modes.. Some functions are missing for sure, that is what I need help to to put in.
What is Serial.In? And what does DEC mean? Serial.println(buttonPushCounter, DEC);
Also; how do I put a loop inside another loop?
When I upload the program, nothing happens for a second, then all LEDs goes on once and then off. This happens without me touching the button...
Thank you for any help on my project.
-Janniche