Help to modify Arduino code

Arduino projects on the go
Scott Todd
Posts: 66
Joined: 26 Mar 2018, 23:21

Re: Help to modify Arduino code

Post by Scott Todd »

I added some Serial.print lines to help with debugging. The millis() is NOT returning a value.

Ugggghh....This has to be something simple...
Attachments
PPM_Encoder4.ino
(11.46 KiB) Downloaded 142 times
jmendoza
Posts: 167
Joined: 18 Feb 2018, 23:07

Re: Help to modify Arduino code

Post by jmendoza »

Hey Scott, I can kick you after 5 minutes, no charge :D
User avatar
Phil_G
Posts: 597
Joined: 15 Feb 2018, 23:32
Contact:

Re: Help to modify Arduino code

Post by Phil_G »

Just an observation Scott, you're not initialising buttonPressedMillis, so it has an unknown value.
When the button is pressed, you assign it a value (the current time), but until then, and during the tests in line 112, it could be anything.
Scott Todd
Posts: 66
Joined: 26 Mar 2018, 23:21

Re: Help to modify Arduino code

Post by Scott Todd »

Good catch Phil. It gets declared in 111 but I see your point. I may go back and re-visit it. I decided to punt and start over. Its boring to most but for the record, here is what I did. I'll add a switched Digital input to select two different values eventually. Again, the point is to do spot landings and 'mini' contests with friends. And get some practice coding again. No matter how simple....

static int timedButton = 2, timerLED=3; //Added by *** Scott Todd ***
unsigned int motorTimer=0, motorCut=0, motorDuration=150; // 50 hz or 50 = 1 second, so 150=3sec for testing

pinMode(timedButton, INPUT_PULLUP); //Added by *** Scott Todd ***
pinMode(timerLED, OUTPUT); //Added by *** Scott Todd ***


// This is added just after inactivity near end of code.
// I added the LED for de-bugging and decided I liked it. It stays on during the timing cycle.
// **** MotorTimer Added by Scott Todd
if (digitalRead(timedButton) == 0) {
motorCut=1;
}
if (motorCut==1) {
motorTimer++;
digitalWrite(timerLED, HIGH);
}
if (motorTimer > motorDuration) {
tlock=1;
motorTimer=0;
motorCut=0;
digitalWrite(timerLED, LOW);
}
Post Reply