int DP_LED = 16;
int Red_LED = 3;
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
int command;
int sensorPin = A0; // input pin for the potentiometer
int digitalValue = 0;// variable to store the value coming from the sensor
// the setup function runs once when you press reset or power the board
void setup() {
Serial1.begin(9600);
pinMode(16, OUTPUT);
pinMode(3, OUTPUT);
Serial1.begin(115200);
delay(100);
Serial1.println("Type s to start!\n");
while(!Serial1.available() > 0);
command = Serial1.read();
if(command == 's'){
Serial1.println("Blinking DP LED every 500ms!");
}
else {
Serial1.println("Command is wrong!");
exit(1);
}
}
// the loop function runs over and over again forever
void loop() {
analogWrite(Red_LED, brightness); // set the brightness of led by changing the PWM value
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
delay(30); // wait for 30 milliseconds to see the dimming effect
digitalWrite(DP_LED, HIGH); // turn the DP LED off (HIGH is the voltage level)
Serial1.print("DP LED is OFF!\n");
delay(500);
digitalWrite(DP_LED, LOW); // turn the DP LED on
Serial1.print("DP LED is ON!\n");
delay(500);
digitalValue = analogRead(sensorPin);// read the value from the analog channel
Serial1.print("digital value = ");
Serial1.println(digitalValue); //print digital value on serial monitor
}