#define lcdLed 10
#define headLight 3
#define modeAuto 5
#define modeMan 7
void setup() {
// initialize serial communication at 9600 bits per second:
pinMode(lcdLed, OUTPUT);
pinMode(headLight, OUTPUT);
pinMode(modeAuto, INPUT);
pinMode(modeMan, INPUT);
digitalWrite(headLight, LOW);
int x = 1;
for (int i = 0; i > -1; i = i + x){
analogWrite(lcdLed, i);
if(i==255){
i=-2;
}
delay(10);
}
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
bool modeA = digitalRead(modeAuto);
bool modeM = digitalRead(modeMan);
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println("sensor");
Serial.println(sensorValue);
Serial.println("Mode");
if (modeA && !modeM){
Serial.println("Automatic Headlight Mode");
}else{
Serial.println("Manual Headlight Mode");
}
Serial.println("Lcd Reading");
Serial.println(analogRead(lcdLed));
Serial.println("-------------------");
delay(1000); // delay in between reads for stability
int x;
if (sensorValue>0 && sensorValue<251){
x = 255;
}else if (sensorValue>250 && sensorValue<501){
x = 210;
}else if (sensorValue>500 && sensorValue<751){
x = 180;
}else{
x = 150;
}
analogWrite(lcdLed, x);
if (sensorValue>800 && modeA && !modeM){
digitalWrite(headLight, HIGH);
}else{
digitalWrite(headLight, LOW);
}
}