Stap 9: Laden programma op Arduino
Nu het volgende programma te uploaden naar je Arduino:
#include
#include #include
#define adres 0x48
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
Const int leftSwitch = 8; //pushbutton const int rightSwitch links = 2; //pushbutton recht
int leftLED = 5; int rightLED = 3; int nightLED = 6; int ledvalue = 0;
int buttonStateLeft = 0; int buttonStateRight = 0;
int lightSensor = A0; int sensorValue = 0;
int auxDio = 11; //auxilary input-output int auxValue = 0; int auxAo = A0; ///analoug uitgang
void setup {//initialize LEDs; pinMode (nightLED, OUTPUT); pinMode (leftLED, OUTPUT); pinMode (rightLED, OUTPUT); //initialize knoppen; pinMode (leftSwitch, INPUT); pinMode (rightSwitch, INPUT);
}
void loop {}
Nacht LED installatieprogramma; TEST LED's werken met analogWrite (rightLED, 100); analogWrite (leftLED, 100);analogWrite(nightLED,100);
sensorValue = analogRead(lightSensor); if(sensorValue < 12) {analogWrite(nightLED,100);} als (sensorValue > 8) {analogWrite(nightLED,0);
} //setup beurt signalen
buttonStateLeft=digitalRead(leftSwitch); Controleer als de drukknop ingedrukt is. Als er, is buttonState hoog; if(buttonStateLeft==High) {//turn LED op, digitalWrite (leftLED, hoge); digitalWrite (rightLED, laag);} else {digitalWrite (leftLED, laag); digitalWrite (rightLED, laag);
}
buttonStateRight=digitalRead(rightSwitch); if(buttonStateRight==High) {digitalWrite(rightLED,HIGH); digitalWrite (leftLED, laag);} else {digitalWrite (rightLED, laag); digitalWrite (leftLED, laag);}
}