Go Down

Topic: I don't understand why this won't work??? (Read 533 times) previous topic - next topic


Dec 04, 2012, 04:41 am Last Edit: Dec 04, 2012, 04:43 am by santoroma17 Reason: 1
im trying to look at an input on pin 3 and if its HIGH then hour++

Its for a binary clock. I didn't show the render code because it works and it just adds clutter. Also i know its not neat, Im just testing. and im new :)

Code: [Select]
int second=0, minute=0, hour=1;
int mUnit = 0;
int hUnit = 0;
int sUnit = 0;
int TempReading;
int TempSensorPin = 0;
int TempSwitch = 1;
int HourUp = 3;
int MinuteUp = 2;
int FinalTemp10;
int Display = 1;
int FinalTemp;
int Column,Row;

int TimeSwitchVal = 0;

int Column6 = 13;
int Column5 = 12;
int Column4 = 11;
int Column3 = 10;
int Column2 = 9;
int Column1 = 8;

int Row1 = 7;
int Row2 = 6;
int Row4 = 5;
int Row8 = 4;

void setup() {
 pinMode(Column6, OUTPUT);
 pinMode(Column5, OUTPUT);
 pinMode(Column4, OUTPUT);
 pinMode(Column3, OUTPUT);
 pinMode(Column2, OUTPUT);
 pinMode(Column1, OUTPUT);

 pinMode(Row1, OUTPUT);
 pinMode(Row2, OUTPUT);
 pinMode(Row4, OUTPUT);
 pinMode(Row8, OUTPUT);
 pinMode(HourUp, INPUT);
 pinMode(2, INPUT);
 pinMode(1, INPUT);
 pinMode(0, INPUT);

void loop() {
 if(Display == 1){
 if(Display == 2){

void Reset(){
 digitalWrite(Column6, HIGH);
 digitalWrite(Column5, HIGH);
 digitalWrite(Column4, HIGH);
 digitalWrite(Column3, HIGH);
 digitalWrite(Column2, HIGH);
 digitalWrite(Column1, HIGH);

 digitalWrite(Row1, LOW);
 digitalWrite(Row2, LOW);
 digitalWrite(Row4, LOW);
 digitalWrite(Row8, LOW);
void CheckTempButtons() {
 //TempSwitchVal = digitalRead(TempSwitch);
// if(digitalRead(TempSwitchVal) == HIGH)
 //  Display = 2;
//  else
 //  Display = 1;

void CheckTimeButtons() {
 TimeSwitchVal = digitalRead(HourUp);
 if(TimeSwitchVal == HIGH)

void print(){
 Serial.print(" degrees C");

void tick(){
 static unsigned long lastTick = 0;
 if (millis() - lastTick >= 1000) {
   lastTick = millis();
 sUnit = second%10;
 mUnit = minute%10;
 hUnit = hour%10;

 if (second >= 60) {
   second = 0;

 if (minute >= 60) {
   minute = 0;
 if (hour >= 24) {
void CalcTemp(){
 TempReading = analogRead(TempSensorPin);
 float voltage = TempReading * 5.0;
 voltage /= 1024.0;
 float TempC = (voltage - 0.5) * 100;
 FinalTemp = (int) TempC;
 FinalTemp10 = FinalTemp % 10;


you dont call CheckTimeButtons() in the main loop that I can see


Dec 04, 2012, 04:40 pm Last Edit: Dec 04, 2012, 04:43 pm by santoroma17 Reason: 1
God im dumb i hade the check tempbutton code and timebutton code in a CheckButton funtion but i split it to see if that was the problem. ill fix it when i get home from school :) heres my origanal reply:

[font=Verdana]"hey Osgeld thanks for the reply. sadly its in the "Tick" funtion so it only checks the buttons once per second. it worked when i had the buttons on analog but if i presses the hour button then the hours would increase but if i pressed minute then both minutes and hours would increase. All i changes was the if statments so it works on digital. but now nothing happends when i press any buttons.. i dont get it."[/font]


You also need to debounce your buttons, check in the playground for details.



Wouldn't having the arduino check the buttons once a second already be debounceing unless you reaction time is worse then one second?????


Wouldn't having the arduino check the buttons once a second already be debounceing unless you reaction time is worse then one second?????

Not really but it will basically be relying on luck to detect a button press. It will only detect a button press if, coincidentally, the user presses the button at the same moment the Arduino checks it. At the very least the user will generally have to hold the button for at least one second to ensure a reading.

Read it every loop and debounce it. This will read it fast and often enough that it will seem like it is always checking the button.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131