#include <TinyDebug.h>
const int redPin = PB2;
const int greenPin = PB1;
const int bluePin = PB0;
int del = 200; // delay
// Setup for outputs
void setup()
{
Debug.begin();
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
digitalWrite(redPin, HIGH);
digitalWrite(bluePin, HIGH);
digitalWrite(greenPin, HIGH);
delay(200);
}
void loop() {
int sensorValue = analogRead(PB3);
Debug.println(sensorValue);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 4.8V):
float voltage = sensorValue * (4.8 / 1023.0);
delay(100);
int value=sensorValue;
if (value<=580 ) {
digitalWrite(redPin, LOW);
delay(del);
digitalWrite(redPin, HIGH);
delay(del/2);
digitalWrite(bluePin, HIGH);
digitalWrite(greenPin, HIGH);
}
else
if (value>580 && value<=600) {
digitalWrite(redPin, LOW );
delay(del);
digitalWrite(bluePin,HIGH);
digitalWrite(greenPin,HIGH);
}
else
if (value>600 && value<=690) {
digitalWrite(greenPin, LOW);
delay(del);
digitalWrite(redPin, HIGH);
digitalWrite(bluePin, HIGH);
}
else
if (value>690 && value<=720) {
digitalWrite(bluePin, LOW);
delay(del);
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
}
else
if (value>720) {
digitalWrite(bluePin, LOW);
delay(del);
digitalWrite(bluePin, HIGH);
delay(del/2);
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
}
delay(100);
}