Dear all
As this is my first post, I will try to explain my problem thoroughly.
I looked around with the search function a bit but couldn't find anything specific that could help me.
I am completely new to Arduino and bought myself a Starter Kit and had a lot of fun with this.
After a day of fooling around I decided to create something useful for myself, a light metronome.
I have 1 display (and a pot meter) which shows the current BPM. Then I have put 2 buttons and 1 LED in between there.
1 button is designed to augment the value of the beat by 1, the other button diminishes it by 1.
Whenever I press 1 of the 2 buttons, the program stops working (also the traces in the monitor stop being printed).
I have basically followed the tutorial here to attach the display, and then I have added the 2 buttons and 1 LED along with that display on my bread board.
Basically we can look at it like this:
________
|arduino|-----screen----button-----LED
Basically, I have no clue if my "chain" is series or parallel. I have almost 0 electrical knowledge.
I take a "branch" from the 5V for the 2 buttons. For the - on the buttons, I have put them directly to the arduino inputs and also put a resistor towards the ground (as a "branch").
For the LED, I +, I led it to the input and for the -, I took a resistor and put it to the ground as a "branch".
My code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int BPM = 120;
int minSwitchState;
int plusSwitchState;
float toDelay;
long previousMillis = 0;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
updateDisplay();
//output LED
pinMode(6, OUTPUT);
//input buttons
pinMode(7, INPUT);
pinMode(8, INPUT);
}
void loop() {
minSwitchState = digitalRead(8);
plusSwitchState = digitalRead(7);
if(minSwitchState == HIGH) {
BPM++;
updateDisplay();
}
if(plusSwitchState == HIGH) {
BPM--;
updateDisplay();
}
unsigned long currentMillis = millis();
if(currentMillis - previousMillis == toDelay) {
digitalWrite(6, HIGH);
previousMillis = currentMillis;
Serial.println(millis() / 100.0);
}else{
digitalWrite(6, LOW);
}
}
void updateDisplay() {
toDelay = 60000.0 / (float) BPM;
lcd.clear();
lcd.print("Kies BPM: ");
lcd.setCursor(0, 1);
lcd.print(BPM);
delay(100);
}
The delay(100) at the end is to give the display time enough to refresh. I know 100 is too much, but else, when I keep pressing the buttons, the numbers go up soooooo rapidly.
I have used a part of code I found here to have no delay for bling LED's. Later on I will propably make the bling longer than 1 milli :).
Thanks in advance!!