Skillnad mellan versioner av "Grove - Flame Sensor"
Rad 65: | Rad 65: | ||
print ("Error") | print ("Error") | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
== More information == | == More information == | ||
http://wiki.seeedstudio.com/Grove-Flame_Sensor/ | http://wiki.seeedstudio.com/Grove-Flame_Sensor/ |
Versionen från 26 oktober 2018 kl. 22.21
Kompatibilitet
- Arduino
- Raspberry Pi
Port
- Digital
Exempelkod
Arduino
#define FLAME_SENSOR 2 //connect SENSOR to digital pin2
#define LED 3 //connect Grove - LED to pin3
void setup()
{
pinsInit();
}
void loop()
{
if(isFlameDetected())
turnOnLED();
else turnOffLED();
}
/********************************/
void pinsInit()
{
pinMode(FLAME_SENSOR, INPUT);
pinMode(LED,OUTPUT);
digitalWrite(LED,LOW);
}
void turnOnLED()
{
digitalWrite(LED,HIGH);
}
void turnOffLED()
{
digitalWrite(LED,LOW);
}
boolean isFlameDetected()
{
if(digitalRead(FLAME_SENSOR))
return false;
else return true;
}
Raspberry Pi
import time
import grovepi
# Connect the Grove Flame Sensor to digital port D2
# SIG,NC,VCC,GND
flame_sensor = 2
grovepi.pinMode(flame_sensor,"INPUT")
while True:
try:
print(grovepi.digitalRead(flame_sensor))
time.sleep(.5)
except IOError:
print ("Error")