Help with Error Messages and/or Problem With Code

Here's the code:

boolean detected_push = false ; boolean state = false ; unsigned long time_pushed = 0L ; boolean previous_button_state = digitalRead (5) ;

void loop () { if (digitalRead (5) == LOW && previous_button_state == HIGH) // button pressed { if (!detected_push && millis () - time_pushed > 20) // debounce check { detected_push = true ; // prevent more toggling till button released again state = !state ; digitalWrite (8, HIGH) ; } else time_pushed = millis () ; } if (detected_push && digitalRead (5) == HIGH) detected_push = false ; }

Here's the Verbose Log:

Arduino: 1.6.1 (Windows 7), Board: "Arduino Uno"

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\hooks.c.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\WInterrupts.c.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\wiring.c.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\wiring_analog.c.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\wiring_digital.c.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\wiring_pulse.c.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\wiring_shift.c.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\abi.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\CDC.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\HardwareSerial.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\HardwareSerial0.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\HardwareSerial1.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\HardwareSerial2.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\HardwareSerial3.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\HID.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\IPAddress.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\main.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\new.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\Print.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\Stream.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\Tone.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\USBCore.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\WMath.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-ar rcs C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\WString.cpp.o

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-gcc -w -Os -Wl,--gc-sections -mmcu=atmega328p -o C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/PowerDrawbar.cpp.elf C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp\PowerDrawbar.cpp.o C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a -LC:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp -lm

C:\Users\Luke\AppData\Local\Temp\build1341424974318593730.tmp/core.a(main.cpp.o): In function `main':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:40: undefined reference to `setup'

collect2.exe: error: ld returned 1 exit status

Error compiling.

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:40: undefined reference to `setup'

You are missing a setup() section.

Please use code tags next time! </> in the menu.

Have you seen with what the IDE opens? That’s the bare minimum. So you need to have a function setup. Even if it’s empty. But here it should not be empty.

The read of the previous state should go there.

boolean detected_push = false ;
boolean state = false ;
unsigned long time_pushed = 0L ;
boolean previous_button_state;

void setup(){
  previous_button_state = digitalRead (5) ;
}

void loop (){
 if (digitalRead (5) == LOW && previous_button_state == HIGH)  // button pressed
 {
   if (!detected_push && millis () - time_pushed > 20)  // debounce check
   {
     detected_push = true ;   // prevent more toggling till button released again
     state = !state ;
     digitalWrite (8, HIGH) ;
   }
   else
     time_pushed = millis () ;
 }
 if (detected_push && digitalRead (5) == HIGH)
   detected_push = false ;
}

Also some tips

  1. For buttons, just use a library. It’s way easier, all the work is already done for you. I can recommend Bounce2.
  2. It’s in C++ more common to use variable name like timePushed then it is to use a underscore.
  3. Give all you’re pins a name. Now you have 5 scattered across your sketch. Just use something like cont byte ButtonPin =5; and use that.