🎨
MadMachine-Examples
  • Introduction
  • About our project
  • Getting Started
  • Tutorial
    • What is SwiftIO
    • How to use IDE
    • Libraries
    • MM SDK
  • Built-In Examples
    • GettingStarted
      • Blink
      • ReadDigitalInput
      • ReadAnalogInput
      • PWMBrightnessControl
    • SimpleIO
      • ButtoncontrolLED
      • BlinkAnalogIn
      • BlinkTimer
      • BrightnessAnalogIn
      • Debounce
      • LEDsBrightnessControl
      • PWMSoundOutput
      • PWMMelody
    • AdvancedIO
      • ILI9341
      • LCD1602
      • MidiPlayer
      • PCA9685
      • SHT3x
      • SSD1315
    • Challenge
      • LCDFamily
      • RobotArm
      • Tetris
    • MakerKit
      • Mission 01 Blink
      • Mission 02 RGB LED
      • Mission 03 Push Button
      • Mission 04 Potentiometer RGB
      • Mission 05 Buzzer
      • Mission 06 Seven Segment Display
      • Mission 07 DC Motor
      • Mission 08 Servo Motor
      • Mission 09 LCD
      • Mission 10 Humiture Sensor
  • Library Reference
  • FAQ
Powered by GitBook
On this page
  • What you need
  • Circuit
  • Tips
  • Code
  • Video
  • See Also
  • References

Was this helpful?

  1. Built-In Examples
  2. MakerKit

Mission 03 Push Button

What you need

Circuit

Tips

Code

/*
  Mission3 Push Button

  The Red LED will be turned on when you press the button.

  The circuit:
  - Use Button Module, and connect it to a Digital Jack. 
  - When the Arduino Sheild is properly plugged in, the LED will be on.

  created 2019
  by Orange J

  Each time the input pin goes from LOW to HIGH (e.g. because of a push-button press), the
  output pin is toggled from LOW to HIGH or HIGH to LOW. There's a minimum delay between toggles
  to debounce the circuit (i.e. to ignore noise). Try solve the issue. This example code is in the public domain.
  Visit madmachine.io for more info.
*/

import SwiftIO


let led = DigitalOut(Id.RED) // Initialize the red onboard led.
let button = DigitalIn(Id.D10) // Initialize an input pin D10 on board.

while true {

    // Read the button value. If it is pressed, turn on the led.
    if button.read() {
        led.write(false)
    } else {
        led.write(true)
    }
}

Video

See Also

References

Last revision 2020/09/10 by Johnson

PreviousMission 02 RGB LEDNextMission 04 Potentiometer RGB

Last updated 4 years ago

Was this helpful?