I need help with making SpeedStacks timer!

Hi,

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");
  }
}

One can conclude from your problem statement that the input pin named pwr is never LOW.

Is anything connected to that pin?

Yes

Cool!

How does that help? I said i connected it, but it doesn't give me a messgage.

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.

I meant that when the button was just pressed

  • LEDs need a series dropping resistors.

  • As mentioned:

pinMode(pwr, INPUT_PULLUP);

For help on this forum, take a couple of minutes to express a complete thought or two, containing some actually useful information.

Good luck with your project!

I added that line to the setup code, but it did not work.

I forgot to add the resistors to the schematic, but I did add them in the project

  • Show us your code now.

  • Show us good images of your wiring.

#include "pitches.h"

int red = 12;
int green = 10;
int blue = 11;

int left_touch = 9;
int right_touch = 6;

int reset = 5;
int pwr = 7;
int save = 8;

void setup()
{
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(left_touch, INPUT_PULLUP);
  pinMode(right_touch, INPUT_PULLUP);
  pinMode(pwr, INPUT_PULLUP);
  pinMode(reset, INPUT_PULLUP);
  pinMode(save, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop()
{
  tone(4, 0, 1000000);
  if (digitalRead(pwr) == LOW)
  {
    Serial.println("TURNED ON");
  }
}

The resistors are 220 ohms

  • Show us good images of your actual wiring.

These pictures are the best I can do: