|
/* 03.020 - Grove momentary button |
|
* |
|
This sketch demonstrates how to use the Grove momentary button. |
|
|
|
The momentary button is a digital device (i.e. it can be "on" or "off" only). |
|
|
|
|
|
Components |
|
---------- |
|
|
|
- Grove Base Shield |
|
- An Arduino Uno compatible board (such as Arduino/Genuino Uno or Seeeduino) |
|
- Grove momentary button |
|
- One Grove cable |
|
|
|
IDE |
|
--- |
|
|
|
Arduino IDE |
|
|
|
Libraries |
|
--------- |
|
|
|
- |
|
|
|
Connections |
|
----------- |
|
|
|
Use a Grove cable to connect the temperature module to Base Shield connector D2. |
|
|
|
Other information |
|
----------------- |
|
|
|
- Use this sketch along side the video lecture 03.020 of Grove For Busy People |
|
- Original example sketch location: http://wiki.seeedstudio.com/Grove-Button/ |
|
- Grove component: https://txplo.re/a8cb6 |
|
|
|
Github Gist |
|
----------- |
|
<script src="https://gist.github.com/futureshocked/d53f230adbc249b3a59571575459f1a2.js"></script> |
|
https://gist.github.com/futureshocked/d53f230adbc249b3a59571575459f1a2 |
|
|
|
For course information, please go to https://techexplorations.com/product/grove-for-busy-people/ |
|
|
|
Created on July 5 2019 by Peter Dalmaris |
|
*/ |
|
|
|
// constants won't change. They're used here to set pin numbers: |
|
const int buttonPin = 4; // digital pin 4 is on Grove connector D4 |
|
const int ledPin = 13; // the number of the build-in LED pin |
|
|
|
// variables will change: |
|
int buttonState = 0; // variable for reading the pushbutton status |
|
|
|
void setup() { |
|
// initialize the LED pin as an output: |
|
pinMode(ledPin, OUTPUT); |
|
// initialize the pushbutton pin as an input: |
|
pinMode(buttonPin, INPUT); |
|
} |
|
|
|
void loop() { |
|
// read the state of the pushbutton value: |
|
buttonState = digitalRead(buttonPin); |
|
|
|
// check if the pushbutton is pressed. If it is, the buttonState is HIGH: |
|
if (buttonState == HIGH) { |
|
// turn LED on: |
|
digitalWrite(ledPin, HIGH); |
|
} else { |
|
// turn LED off: |
|
digitalWrite(ledPin, LOW); |
|
} |
|
} |