132
edits
No edit summary |
No edit summary |
||
Line 34: | Line 34: | ||
'''Arduino''' | '''Arduino''' | ||
<source lang="java"> | |||
//*Arduino, rotary encoder code | |||
// this sketch use the five feet rotary encoder. | |||
// it includes an "endless" potentiometer and a button. | |||
// Encoder hooked up with common to GROUND, | |||
// encoder0PinA to pin 3, encoder0PinB to pin 4(could be exchange depends on the value) | |||
int val; | |||
int encoder0PinA = 3; | |||
int encoder0PinB = 4; | |||
//define encoder0PinA | |||
//define encoder0PinB | |||
int encoder0Pos = 0; | |||
int encoder0PinALast = LOW; | |||
int n = LOW; | |||
int myButtonPin=10; //define button on the encoder | |||
int myLedPin=13; | |||
int myButtonState = 0; | |||
void setup() { | |||
pinMode(myButtonPin, INPUT); | |||
pinMode(myLedPin, OUTPUT); | |||
//setup button | |||
pinMode (encoder0PinA,INPUT); | |||
digitalWrite(encoder0PinA,HIGH); | |||
pinMode (encoder0PinB,INPUT); | |||
digitalWrite(encoder0PinB,HIGH); | |||
Serial.begin (9600); | |||
} | |||
void loop() { | |||
int myButtonState = digitalRead(myButtonPin); | |||
if(myButtonState == HIGH){ | |||
digitalWrite(myLedPin, HIGH); | |||
}else{ | |||
digitalWrite(myLedPin, LOW); | |||
} //button control the Led to test | |||
n = digitalRead(encoder0PinA); | |||
if ((encoder0PinALast == LOW) && (n == HIGH)) { | |||
if (digitalRead(encoder0PinB) == LOW) { | |||
encoder0Pos--; | |||
} else { | |||
encoder0Pos++; | |||
} | |||
Serial.print (encoder0Pos); | |||
Serial.println ("/"); | |||
} | |||
encoder0PinALast = n; | |||
} | |||
</source> | |||
<br /><br /> | |||
edits