Difference between revisions of "Time is a technology"
From Lahaag - Project wiki
Jump to navigationJump to searchLine 1: | Line 1: | ||
code for arduino | code for arduino | ||
+ | |||
+ | https://web.archive.org/web/20120105015729/http://wiki.makerbot.com/mre2 | ||
+ | |||
using the makerbot magnetic rotary encoder v2.1 | using the makerbot magnetic rotary encoder v2.1 | ||
Line 28: | Line 31: | ||
− | void read_quadrature() | + | void read_quadrature(){ // found a low-to-high on channel A if (digitalRead(ENCODER_A_PIN) == HIGH) { // check channel B to see which way if (digitalRead(ENCODER_B_PIN) == LOW) position++; else position--; } // found a high-to-low on channel A else { // check channel B to see which way if (digitalRead(ENCODER_B_PIN) == LOW) position--; else position++; }}</syntaxhighlight> |
− | { | ||
− | |||
− | |||
− | |||
− | |||
− | if (digitalRead(ENCODER_B_PIN) == LOW) | ||
− | position++; | ||
− | else | ||
− | position--; | ||
− | } | ||
− | // found a high-to-low on channel A | ||
− | else | ||
− | { // check channel B to see which way | ||
− | if (digitalRead(ENCODER_B_PIN) == LOW) | ||
− | position--; | ||
− | else | ||
− | position++; | ||
− | } | ||
− | } | ||
− | </syntaxhighlight> |
Revision as of 19:44, 29 January 2014
code for arduino
https://web.archive.org/web/20120105015729/http://wiki.makerbot.com/mre2
using the makerbot magnetic rotary encoder v2.1
here is the code
#define ENCODER_A_PIN 2
#define ENCODER_B_PIN 3
long position;
void setup()
{
Serial.begin(19200);
Serial.println("Started");
pinMode(ENCODER_A_PIN, INPUT);
pinMode(ENCODER_B_PIN, INPUT);
attachInterrupt(0, read_quadrature, CHANGE);
}
void loop()
{
Serial.print("Position: ");
Serial.println(position, DEC);
delay(1000);
}
void read_quadrature(){ // found a low-to-high on channel A if (digitalRead(ENCODER_A_PIN) == HIGH) { // check channel B to see which way if (digitalRead(ENCODER_B_PIN) == LOW) position++; else position--; } // found a high-to-low on channel A else { // check channel B to see which way if (digitalRead(ENCODER_B_PIN) == LOW) position--; else position++; }}