Modification du code driver DC + Ajout code de test
This commit is contained in:
36
Moteur DC/Test/Test_Roue_Codeuse/Test_Roue_Codeuse.ino
Normal file
36
Moteur DC/Test/Test_Roue_Codeuse/Test_Roue_Codeuse.ino
Normal file
@@ -0,0 +1,36 @@
|
||||
/* Read Quadrature Encoder
|
||||
* Connect Encoder to Pins encoder0PinA, encoder0PinB, and +5V.
|
||||
*
|
||||
* Sketch by max wolf / www.meso.net
|
||||
* v. 0.1 - very basic functions - mw 20061220
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
int val;
|
||||
int encoder0PinA = 7;
|
||||
int encoder0PinB = 8;
|
||||
int encoder0Pos = 0;
|
||||
int encoder0PinALast = LOW;
|
||||
int n = LOW;
|
||||
|
||||
void setup() {
|
||||
pinMode (encoder0PinA,INPUT);
|
||||
pinMode (encoder0PinB,INPUT);
|
||||
Serial.begin (9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
n = digitalRead(encoder0PinA);
|
||||
if ((encoder0PinALast == LOW) && (n == HIGH)) {
|
||||
if (digitalRead(encoder0PinB) == LOW) {
|
||||
encoder0Pos--;
|
||||
} else {
|
||||
encoder0Pos++;
|
||||
}
|
||||
Serial.print (encoder0Pos);
|
||||
Serial.print ("\n");
|
||||
}
|
||||
encoder0PinALast = n;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user