Stap 3: Programmering/Code
Download het bestand aan het einde van de instructable of kopieer de volgende code in jouw Arduino-Intel IDE (Integrated Development Environment). Upload de code naar de Edison-bestuur.
//This code drives a light transmission meter.//Pressing the button calibrates the light intensity meter to 100% //The LCD screen displays the brightness relative to the calibration mark. //LED wired through analog pin ~3, and light intensity through A0. //Button through D7
#include #include
rgb_lcd lcd;
int ledPin = 3; int buttonPin = 7; int lightPin = A0; int maxBrightness = 0; int minBrightness = 255;
int maxLightIntensity = 1023;
void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT); analogWrite(ledPin, maxBrightness); lcd.begin(16,2);//Configure the number of rows and columns on the lcd screen lcd.setRGB(255,255,255); }
void loop() { if(digitalRead(buttonPin)==HIGH){ maxLightIntensity = analogRead(lightPin); } double percent = 100*((double)analogRead(lightPin))/maxLightIntensity; lcd.setCursor(0,0); lcd.print(" ");//Clear LCD screen lcd.setCursor(0,0); lcd.print("Percent: "); lcd.print(percent); lcd.print("%"); delay(100); }