I'm trying to make a SpeedStacks timer, with buttons. Right now, it's supposed to print a message to the serial monitor at 9600 baud. It does not work, though. Here's my code:
#include "pitches.h" //library
int red = 12; //rgb led
int green = 11; //rgb led
int blue = 10; //rgb led
int left_touch = 9; //right button for timer
int right_touch = 6; //left button for timer
int reset = 5; //reset button
int pwr = 7; //power button (have issue regarding this)
int save = 8; //save button (to save PBs)
void setup()
{
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(left_touch, INPUT_PULLUP);
pinMode(right_touch, INPUT_PULLUP);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(pwr) == LOW)
{
Serial.println("TURNED ON");
}
}
Let's make this a bit easier for us to answer your question. Post an annotated schematic showing exactly how you have wired this. Show all connections etc. Hint I do not read word problems or frizzies but schematics work great.
Fritzing diagrams are generally uninterpretable in detail, and often misleading or completely wrong, but the one you posted suggests that you have a button wired to pin 7.
The code in turn suggests that the button never sets a LOW state on pin 7, because nothing is printed.
So, you might check the wiring and use your multimeter to determine whether the button actually does connect pin 7 to ground when pressed.
It is a good idea to declare that pin as INPUT_PULLUP in the code, so that the input state when the button is not pressed is defined as HIGH. The default pin state is INPUT.
In the future, please don't bother to post Fritzing diagrams. Schematic diagrams are the universal language of electronics, and it is easy to learn how to read and draw them.