KY-002: Skillnad mellan sidversioner
(→Bild) |
|||
Rad 15: | Rad 15: | ||
<pre> | <pre> | ||
int LED = 13 ;// define LED pin | int LED = 13 ;// define LED pin | ||
int | int SENSOR = 2; // sensor pin | ||
int val ; // define numeric variable val | int val ; // define numeric variable val | ||
void setup () | void setup () | ||
{ | { | ||
pinMode (LED, OUTPUT) ; // define LED as output | pinMode (LED, OUTPUT) ; // define LED as output | ||
pinMode ( | pinMode (SENSOR, INPUT) ; // define SENSOR as input | ||
} | } | ||
void loop () | void loop () | ||
{ | { | ||
val = digitalRead ( | val = digitalRead (SENSOR) ;// read SENSOR and put it into val | ||
if (val == HIGH) // When the | if (val == HIGH) // When the sensor detects a signal, LED flashes | ||
{ | { | ||
digitalWrite (LED, LOW); | digitalWrite (LED, LOW); |
Versionen från 9 oktober 2013 kl. 15.09
Bild
Om sensorn
Shock är en stötsensor som skickar ut HIGH på signalstiftet när den får en stöt/vibration
Synonymer
KEYES Shock Module, KY002, Hit sensor module, 02 ARDUINO vibration switch module
Koppling
Arduino exempelkod
int LED = 13 ;// define LED pin int SENSOR = 2; // sensor pin int val ; // define numeric variable val void setup () { pinMode (LED, OUTPUT) ; // define LED as output pinMode (SENSOR, INPUT) ; // define SENSOR as input } void loop () { val = digitalRead (SENSOR) ;// read SENSOR and put it into val if (val == HIGH) // When the sensor detects a signal, LED flashes { digitalWrite (LED, LOW); } else { digitalWrite (LED, HIGH); } }