Go Down

Topic: Self made shake switch (Read 1 time) previous topic - next topic

Samory

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

Code: [Select]
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);
}
}

Go Up