const int kPinPot1 = A0;
const int kPinPot2 = A1;
const int kPinPot3 = A2;
const int kPinLed_R = 6;
const int kPinLed_G = 10;
const int kPinLed_B = 11;
const int kPinGasButton = 2;
const int kPinBrakeButton = 3;
const int kPinSpeedLed = 9;
int speed = 0;
const int maxSpeed = 255;
const int minSpeed = 0;
const int speedIncrement = 5;
void setup() {
pinMode(kPinLed_R, OUTPUT);
pinMode(kPinLed_G, OUTPUT);
pinMode(kPinLed_B, OUTPUT);
pinMode(kPinGasButton, INPUT_PULLUP);
pinMode(kPinBrakeButton, INPUT_PULLUP);
pinMode(kPinSpeedLed, OUTPUT);
}
void loop() {
int potValue;
int ledValue;
potValue = analogRead(kPinPot1);
ledValue = map(potValue, 0, 1023, 0, 255);
analogWrite(kPinLed_R, ledValue);
potValue = analogRead(kPinPot2);
ledValue = map(potValue, 0, 1023, 0, 255);
analogWrite(kPinLed_G, ledValue);
potValue = analogRead(kPinPot3);
ledValue = map(potValue, 0, 1023, 0, 255);
analogWrite(kPinLed_B, ledValue);
if (digitalRead(kPinGasButton) == LOW) {
speed += speedIncrement;
if (speed > maxSpeed) {
speed = maxSpeed;
}
}
if (digitalRead(kPinBrakeButton) == LOW) {
speed -= speedIncrement;
if (speed < minSpeed) {
speed = minSpeed;
}
}
analogWrite(kPinSpeedLed, speed);
delay(100);
}