Intellekten Galileo Gen 2 ljussensor med utsäde Studio startpaket (4 / 4 steg)
Steg 4: kod
På Atmel Studio... Skapa ett nytt C/C++-projekt
Du kan fortfarande helt enkelt ladda Arduino IDE om Atmel inte är din sak...
Koden
#include < math.h >
#include < Wire.h >
#include "rgb_lcd.h"
rgb_lcd lcd;
CONST int colorR = 255;
CONST int colorG = 0;
CONST int colorB = 0;
CONST int ledPin = 12;
CONST int thresholdvalue = 10;
float Rsensor;
void setup() {
LCD.BEGIN (16, 2);
lcd.setRGB (colorR, colorG, colorB);
pinMode(ledPin,OUTPUT);
Delay(1000);
}
void loop() {
int sensorValue = analogRead(0);
Rsensor=(float) (1023-sensorValue) * 10/sensorValue;
IF(Rsensor>thresholdvalue)
{
digitalWrite(ledPin,HIGH);
}
annat
{
digitalWrite(ledPin,LOW);
}
lcd.setCursor (0, 0);
LCD.Print ("Data:" + sensorValue);
lcd.setCursor (1, 1);
LCD.Print ("Res:" + Rsensor); //Resistance
Delay(1000);
}