Skillnad mellan versioner av "Grove - Flame Sensor"
Rad 5: | Rad 5: | ||
== Port == | == Port == | ||
− | Digital | + | *Digital |
== Exempelkod == | == Exempelkod == | ||
Rad 46: | Rad 46: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === Raspberry Pi | + | === Raspberry Pi === |
<syntaxhighlight lang="Python" line> | <syntaxhighlight lang="Python" line> | ||
import time | import time |
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")