Pages: 1 [2]   Go Down
Author Topic: Self made shake switch  (Read 1411 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now I have something like a basic code, but It still isn't working! ;(

Code:
int value = 0;
 
const int in4Pin = 4;
const int led8Pin = 8;
const int led7Pin = 7;
int buttonPushCounter = 0;   
int buttonState = 0;         
int lastButtonState = 0;   
 
 
void setup()
{
  pinMode(in4Pin, INPUT);
  pinMode(led7Pin, OUTPUT);
  pinMode(led8Pin, OUTPUT);
 
   Serial.begin(9600);
 
}
 
 
void loop() {
 
   buttonState = digitalRead(in4Pin);
 
   if (buttonState != lastButtonState) {
      if (buttonState == HIGH) {
        buttonPushCounter++;
       Serial.println("on");
       Serial.print("number of button pushes:  ");
       Serial.println(buttonPushCounter, DEC);
     }
    else {
        Serial.println("off");
    }
   }
    lastButtonState = buttonState;
 if (buttonPushCounter == 10 )
{
   digitalWrite(led7Pin, HIGH);
   digitalWrite(led8Pin, HIGH);
  } else {
   digitalWrite(led7Pin, LOW);
    digitalWrite(led8Pin, LOW);
}
}
Logged

Pages: 1 [2]   Go Up
Jump to: