I've broken my issue down to it's simplest form. I have a tilt switch (practically a button that is HIGH when right side up and LOW when upside down) and an LED. What I'm gathering from trial and error is that my loop function isn't actually looping, it's just reading the switch once and acting accordingly with the if-else statement. I'd like it to loop repeatedly and constantly read and act depending on the switch. It's probably a very beginner syntax issue but I haven't found it yet. I am using an arduino uno r3.
You need to update ‘press’ in the loop function.
void loop()
{
press = digitalRead(button);
. . .
BTW
No images of code please.
Always show us your ‘current’ complete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.
[code] Paste sketch here. [/code]
Must read the switch every time in loop()
Try this.
Leo..
const byte switchPin = 2; // switch between pin and ground, NO pull up/down resistor
const byte ledPin = 13; // buildin LED
void setup() {
pinMode(switchPin, INPUT_PULLUP); // enable internal pull up resistor
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, digitalRead(switchPin)); // LED follows switch
delay(100); // don't update more than 10x/sec
}