Toggle Switch

Toggle Switch Toggle Switch

The toggle switch is a simple switch. When the switch is at the end labeled "on", it makes an electrical connection. The Arduino can detect this electrical connection. Then it can figure out of the switch is set to "on" or "off".

Main Function

awesome.toggleSwitch.isOn()

Checks if the switch is set to "on".

Returns

It returns a bool. This bool is true if the switch is set to "on" and false if it is set to "off".

Example

// Turns the LED on if switch is set to on if ( awesome.toggleSwitch.isOn() ) { awesome.LED.turnOn(); }

Advanced Functions

awesome.toggleSwitch.isOff()

Checks if the switch is set to "off".

Returns

It returns a bool. This bool is true if the switch is set to "off" and false if it is set to "on".

Example

// Turns the LED off if switch is set to OFF if ( awesome.toggleSwitch.isOff() ) { awesome.LED.turnOff(); }

awesome.toggleSwitch.print()

First the print function takes a reading from the toggle switch to see if it is set to on or off. Then it sends a message telling you whether the toggle switch is on or off through the Serial connection.

Click the magnifying glass icon in the top right hand corner of the Arduino IDE to see the messages that Arduino sends to you through the Serial connection.

Example

awesome.toggleSwitch.print();

Tips

You can use the toggle switch to change your sketch from one mode to another. For example, one mode could silence the buzzer. It works well with if().

x

Goodbye and thanks for all the fish,

Thanks for helping us Kickstart Awesome Shield and learning with us. Sadly, turning Awesome Shield into a sustainable business didn’t work out and so we’re in the process of officially shutting down the company.

Read our full letter.

If you have an Awesome Shield you can keep using it and the learning platform.


Close Message