100 lines
1.6 KiB
C++
100 lines
1.6 KiB
C++
|
|
int vol0, vol1, vol2, vol3, vol4;
|
|
|
|
int changeRange = 20;
|
|
|
|
int red = 9;
|
|
int green = 10;
|
|
int blue = 11;
|
|
|
|
|
|
// The setup() function runs once each time the micro-controller starts
|
|
void setup()
|
|
{
|
|
|
|
pinMode(A0, INPUT);
|
|
pinMode(A1, INPUT);
|
|
pinMode(A2, INPUT);
|
|
pinMode(A3, INPUT);
|
|
pinMode(A4, INPUT);
|
|
|
|
|
|
pinMode(9, OUTPUT);
|
|
pinMode(10, OUTPUT);
|
|
pinMode(11, OUTPUT);
|
|
|
|
|
|
Serial.begin(4800);
|
|
|
|
while (!Serial);
|
|
Serial.println();
|
|
Serial.println("OK");
|
|
Serial.flush();
|
|
|
|
|
|
vol0 = analogRead(A0);
|
|
vol1 = analogRead(A1);
|
|
vol2 = analogRead(A2);
|
|
vol3 = analogRead(A3);
|
|
vol4 = analogRead(A4);
|
|
|
|
analogWrite(red, 180);
|
|
analogWrite(green, 0);
|
|
analogWrite(blue, 200);
|
|
|
|
}
|
|
|
|
// Add the main program code into the continuous loop() function
|
|
void loop()
|
|
{
|
|
delay(400);
|
|
|
|
int pot0 = analogRead(A0);
|
|
int pot1 = analogRead(A1);
|
|
int pot2 = analogRead(A2);
|
|
int pot3 = analogRead(A3);
|
|
int pot4 = analogRead(A4);
|
|
|
|
if (shouldChangeVolume(vol0, pot0))
|
|
{
|
|
Serial.print("NUOVO VALORE 0: ");
|
|
Serial.println(pot0);
|
|
vol0 = pot0;
|
|
}
|
|
|
|
if (shouldChangeVolume(vol1, pot1))
|
|
{
|
|
Serial.print("NUOVO VALORE 1: ");
|
|
Serial.println(pot1);
|
|
vol1 = pot1;
|
|
}
|
|
if (shouldChangeVolume(vol2, pot2))
|
|
{
|
|
Serial.print("NUOVO VALORE 2: ");
|
|
Serial.println(pot2);
|
|
vol2 = pot2;
|
|
}
|
|
if (shouldChangeVolume(vol3, pot3))
|
|
{
|
|
Serial.print("NUOVO VALORE 3: ");
|
|
Serial.println(pot3);
|
|
vol3 = pot3;
|
|
}
|
|
if (shouldChangeVolume(vol4, pot4))
|
|
{
|
|
Serial.print("NUOVO VALORE 4: ");
|
|
Serial.println(pot4);
|
|
vol4 = pot4;
|
|
}
|
|
|
|
}
|
|
|
|
boolean shouldChangeVolume(int oldValue, int newValue)
|
|
{
|
|
|
|
int diff = oldValue - newValue;
|
|
|
|
if (diff < -changeRange || diff > changeRange) return true;
|
|
return false;
|
|
}
|