Start/stop a turntable with toggle pushbutton

[quote="dlloyd, post:6, topic:998544"]

#include <Toggle.h>

....[/quote]

indeed very easy to use. Hides away all the details from the user.

For a real newcomer the sourcecode must have a lot of basic comments to explain what is important.
If a library becomes popular or not depends a lot from how easy is it to modify. And does the source-code teach important basics.

So here is a version of your democode with additional commands and selfexplaining names

// you can install the toogle.h-library with the library-manager 
// inside the Arduino-IDE which is the most comfortable way
// or through downloading the ZIP-file from here https://github.com/Dlloydev/Toggle
// and installing as a ZIP-library
#include <Toggle.h> // this line adds the code inside the file Toggle.h that makes it work

const byte myTestButton  =  4;
const byte OnBoardLedPin = 13; // take Arduino-Uno / Mega Onboard LED 

byte LED_State;

Toggle myButton(myTestButton); // create object that uses IO-pin myTestButton 

void setup() {
  myButton.begin(myTestButton); // start the button-object 
  pinMode(OnBoardLedPin, OUTPUT);
}

void loop() {
  // the function poll() must be called very often 
  // to read in and update the actual state of the button
  myButton.poll(); 

  // the function toggle() returns the state of a SOFWTARE EMULATED latched button
  // after a first  press of the button the function returns a "1" like I'm in ON-mode
  // after the next press of the button the function returns a "0" like I'm in OFF-mode
  // after the next press of the button the function returns a "1" like I'm in ON-mode
  // etc. etc. etc. etc. etc. ....
  // this means that only AFTER releasing the button and then
  // pressing DOWN the button NEW 
  // the value that function toggle() returns is CHANGED 
  LED_State = myButton.toggle();
  digitalWrite(OnBoardLedPin, LED_State);
}

best regards Stefan

1 Like