Potmeter lezer
Sluit de Potmeter(s) aan vanaf A0 tot A5. de linker en rechter aansluiting van de potmeter is bijna altijd de plus en de min. de Middelste is het genen wat we willen gaan uitlezen dus die moet op de A# aansluitingen.
En sluit de Arduino aan op de PC. (vergeet het onderstaande programma niet te uploaden naar de Arduino! als je nu een seriële verbinding legt met de Arduino (Dat kan gewooon met de "Serieele monitor" dat in het Arduino programeer programma zit) vraagt de Arduino hoeveel potmeters er zijn aangesloten. typ een getal tussen de 0 en 6 in; en de Arduino zal er zoveel contenu uitlezen totdat je stopt, of een ander nummer doorgeeft.
En sluit de Arduino aan op de PC. (vergeet het onderstaande programma niet te uploaden naar de Arduino! als je nu een seriële verbinding legt met de Arduino (Dat kan gewooon met de "Serieele monitor" dat in het Arduino programeer programma zit) vraagt de Arduino hoeveel potmeters er zijn aangesloten. typ een getal tussen de 0 en 6 in; en de Arduino zal er zoveel contenu uitlezen totdat je stopt, of een ander nummer doorgeeft.
De Code van de Arduino
//This code is written by Jelle Wie WWW.Jellewie.Weebly.Com
//
int PinPot0 = 0;
int PinPot1 = 1;
int PinPot2 = 2;
int PinPot3 = 3;
int PinPot4 = 4;
int PinPot5 = 5;
int ValPot0 = 0;
int ValPot1 = 0;
int ValPot2 = 0;
int ValPot3 = 0;
int ValPot4 = 0;
int ValPot5 = 0;
int TotalPots = 0;
int Restart = 0;
int ReadIncomming = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
//MSG on start
if (Restart == 0) {
Serial.println("How many potmeters are there?");
Restart = 1;
}
//Check serial
if (Serial.available() > 0) {
ReadIncomming = Serial.read();
TotalPots = 0;
if (ReadIncomming == 48) {
TotalPots = 0;
} else if (ReadIncomming == 49) {
TotalPots = 1;
} else if (ReadIncomming == 50) {
TotalPots = 2;
} else if (ReadIncomming == 51) {
TotalPots = 3;
} else if (ReadIncomming == 52) {
TotalPots = 4;
} else if (ReadIncomming == 53) {
TotalPots = 5;
} else if (ReadIncomming == 54) {
TotalPots = 6;
} else {
TotalPots = -1;
Serial.println("I need a number between 0-6");
}
if (TotalPots > -1){
Serial.print("Reading ");
Serial.print(TotalPots);
Serial.println(" Potmeters ");
delay(250);
}
}
//Print # potmeters
if (TotalPots > 0) {
ValPot0 = analogRead(PinPot0);
Serial.print("A");
Serial.print(PinPot0);
Serial.print(" ");
Serial.print(ValPot0);
Serial.print("\t");
Serial.print("\t");
}
if (TotalPots > 1) {
ValPot1 = analogRead(PinPot1);
Serial.print("A");
Serial.print(PinPot1);
Serial.print(" ");
Serial.print(ValPot1);
Serial.print("\t");
Serial.print("\t");
}
if (TotalPots > 2) {
ValPot2 = analogRead(PinPot2);
Serial.print("A");
Serial.print(PinPot2);
Serial.print(" ");
Serial.print(ValPot2);
Serial.print("\t");
Serial.print("\t");
}
if (TotalPots > 3) {
ValPot3 = analogRead(PinPot3);
Serial.print("A");
Serial.print(PinPot3);
Serial.print(" ");
Serial.print(ValPot3);
Serial.print("\t");
Serial.print("\t");
}
if (TotalPots > 4) {
ValPot4 = analogRead(PinPot4);
Serial.print("A");
Serial.print(PinPot4);
Serial.print(" ");
Serial.print(ValPot4);
Serial.print("\t");
Serial.print("\t");
}
if (TotalPots > 5) {
ValPot5 = analogRead(PinPot5);
Serial.print("A");
Serial.print(PinPot5);
Serial.print(" ");
Serial.print(ValPot5);
Serial.print("\t");
}
//add a enter after last potmeter reading
if (TotalPots > 0){
Serial.println();
//DIT IS DE TIJD IN MILLISECONDE DAT HIJ WACHT TUSSEN HET PRINTEN, IVM DAT JE ANDERS NIKS KAN LEZEN OMDAT HET TE SNEL GAAT
delay(200);
}
}
//
int PinPot0 = 0;
int PinPot1 = 1;
int PinPot2 = 2;
int PinPot3 = 3;
int PinPot4 = 4;
int PinPot5 = 5;
int ValPot0 = 0;
int ValPot1 = 0;
int ValPot2 = 0;
int ValPot3 = 0;
int ValPot4 = 0;
int ValPot5 = 0;
int TotalPots = 0;
int Restart = 0;
int ReadIncomming = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
//MSG on start
if (Restart == 0) {
Serial.println("How many potmeters are there?");
Restart = 1;
}
//Check serial
if (Serial.available() > 0) {
ReadIncomming = Serial.read();
TotalPots = 0;
if (ReadIncomming == 48) {
TotalPots = 0;
} else if (ReadIncomming == 49) {
TotalPots = 1;
} else if (ReadIncomming == 50) {
TotalPots = 2;
} else if (ReadIncomming == 51) {
TotalPots = 3;
} else if (ReadIncomming == 52) {
TotalPots = 4;
} else if (ReadIncomming == 53) {
TotalPots = 5;
} else if (ReadIncomming == 54) {
TotalPots = 6;
} else {
TotalPots = -1;
Serial.println("I need a number between 0-6");
}
if (TotalPots > -1){
Serial.print("Reading ");
Serial.print(TotalPots);
Serial.println(" Potmeters ");
delay(250);
}
}
//Print # potmeters
if (TotalPots > 0) {
ValPot0 = analogRead(PinPot0);
Serial.print("A");
Serial.print(PinPot0);
Serial.print(" ");
Serial.print(ValPot0);
Serial.print("\t");
Serial.print("\t");
}
if (TotalPots > 1) {
ValPot1 = analogRead(PinPot1);
Serial.print("A");
Serial.print(PinPot1);
Serial.print(" ");
Serial.print(ValPot1);
Serial.print("\t");
Serial.print("\t");
}
if (TotalPots > 2) {
ValPot2 = analogRead(PinPot2);
Serial.print("A");
Serial.print(PinPot2);
Serial.print(" ");
Serial.print(ValPot2);
Serial.print("\t");
Serial.print("\t");
}
if (TotalPots > 3) {
ValPot3 = analogRead(PinPot3);
Serial.print("A");
Serial.print(PinPot3);
Serial.print(" ");
Serial.print(ValPot3);
Serial.print("\t");
Serial.print("\t");
}
if (TotalPots > 4) {
ValPot4 = analogRead(PinPot4);
Serial.print("A");
Serial.print(PinPot4);
Serial.print(" ");
Serial.print(ValPot4);
Serial.print("\t");
Serial.print("\t");
}
if (TotalPots > 5) {
ValPot5 = analogRead(PinPot5);
Serial.print("A");
Serial.print(PinPot5);
Serial.print(" ");
Serial.print(ValPot5);
Serial.print("\t");
}
//add a enter after last potmeter reading
if (TotalPots > 0){
Serial.println();
//DIT IS DE TIJD IN MILLISECONDE DAT HIJ WACHT TUSSEN HET PRINTEN, IVM DAT JE ANDERS NIKS KAN LEZEN OMDAT HET TE SNEL GAAT
delay(200);
}
}