#define PotPin A0
#define RLed D11
#define GLed D10
#define BLed D9
void writergb(bool r, bool g, bool b);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, STM32!");
pinMode(RLed, OUTPUT);
pinMode(GLed, OUTPUT);
pinMode(BLed, OUTPUT);
writergb(LOW, LOW, LOW);
}
void loop() {
Serial.print("PotVal:");
Serial.println(analogRead(PotPin));
if ((analogRead(PotPin) > 10) && (analogRead(PotPin) < 101))
{
writergb(HIGH, LOW, LOW);
} else if ((analogRead(PotPin) > 100) && (analogRead(PotPin) < 500))
{
writergb(LOW, HIGH, LOW);
} else if (analogRead(PotPin) > 499)
{
writergb(LOW, LOW, HIGH);
}
else {
writergb(LOW, LOW, LOW);
}
delay(10); // this speeds up the simulation
}
void writergb(bool r, bool g, bool b)
{
digitalWrite(RLed, r);
digitalWrite(GLed, g);
digitalWrite(BLed, b);
}