Some of you might remember my previous Chronodot-related posts. I'm trying to make an alarm clock, basically. There are several parts to this program—one part is the Chronodot code (which I pretty much took directly from chronodot [macetech documentation]), and another part is a button system with three push-button switches, one to go from displaying the time to setting the alarm, one to choose the hours, and one to choose the minutes. However, for some reason, I think my Chronodot code is conflicting with the button system, because whenever I comment out the Chronodot code, the buttons work perfectly fine, but when I keep the Chronodot code in there, I always have to press the buttons a MILLION times in order for them to work.
Does anybody have ANY clue what is going on? I hardly have any experience with I2C/similar protocols, so I really have no idea what to make of this.
For reference, my code is attached to this message.
val = analogRead(analogPin); // read the input pin
Serial.print("Analog value =\t");
y = (772.92 * 9.723 * 1/(val))*(5/2.5);
Serial.println(y); // debug value
delay(500); <<< this 1/2 second delay means your button pushes are ignored a lot of the time.
It's a sensor-based alarm clock—I'm having a motor lower an object down at a speed that's determined by the time the user punches in. Once the sensor detects the object at a certain distance, the alarm will go off. I haven't written that part of the program yet, but I figured I would use the physics equation v = d/t and find a way to convert the speed to an analog value within 0-255 so that it gets fed into the H-bridge I'm using.
Yeah, sorry if that didn't make much sense and if I digressed a little.
Really, so you think it could be that delay that's causing all my problems? I have that there just because of the serial.print() function. I'm printing the analog values for debugging purposes, and I don't want all the values to come spurting out at once.
I dunno if it's the delay though, because one of my buttons started to work just fine as soon as I moved the following part of my code out of loop() and up where I declare all my variables at the beginning:
int seconds = Wire.receive(); // get seconds
int minutes = Wire.receive(); // get minutes
int hours = Wire.receive(); // get hours
I have that there just because of the serial.print() function. I'm printing the analog values for debugging purposes, and I don't want all the values to come spurting out at once.
Then only actually print it out every half second in the manor of the blink without delay example.
so you think it could be that delay that's causing all my problems
It could be, is it better if you hold the button down?
You guys were right, it was a delay in my program. It wasn't that particular delay, but it was a different delay that came after all my conditional statements, right before the end of the loop() function. It's working just fine now; thanks so much for all your help!