Skip to content

Commit 433e210

Browse files
authored
Merge pull request #1821 from ladyada/master
demo for p5201
2 parents d2174e5 + 3b98c6a commit 433e210

3 files changed

Lines changed: 85 additions & 1 deletion

File tree

ANO_encoder_demo/.feather_m0_express.test.only

Whitespace-only changes.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include <Adafruit_NeoPixel.h>
2+
#include <RotaryEncoder.h>
3+
4+
#define PIN_ENCODER_A 12
5+
#define PIN_ENCODER_B 13
6+
#define COM_A 11 // for wiring simplicity we set these output LOW
7+
#define COM_B SDA // ... but you can just wire these to GND instead!
8+
#define BUTTON_UP SCL
9+
#define BUTTON_LEFT 5
10+
#define BUTTON_DOWN 6
11+
#define BUTTON_RIGHT 9
12+
#define BUTTON_IN 10
13+
14+
RotaryEncoder encoder(PIN_ENCODER_A, PIN_ENCODER_B, RotaryEncoder::LatchMode::TWO03);
15+
// This interrupt will do our encoder reading/checking!
16+
void checkPosition() {
17+
encoder.tick(); // just call tick() to check the state.
18+
}
19+
int last_rotary = 0;
20+
21+
22+
#define NUMPIXELS 12
23+
Adafruit_NeoPixel pixels(NUMPIXELS, A0, NEO_GRB + NEO_KHZ800);
24+
25+
26+
void setup(void) {
27+
Serial.begin(115200);
28+
// while (!Serial);
29+
Serial.println("ANO encoder + NeoPixel test");
30+
31+
pinMode(COM_A, OUTPUT);
32+
digitalWrite(COM_A, LOW);
33+
pinMode(COM_B, OUTPUT);
34+
digitalWrite(COM_B, LOW);
35+
36+
attachInterrupt(PIN_ENCODER_A, checkPosition, CHANGE);
37+
attachInterrupt(PIN_ENCODER_B, checkPosition, CHANGE);
38+
39+
pinMode(BUTTON_UP, INPUT_PULLUP);
40+
pinMode(BUTTON_DOWN, INPUT_PULLUP);
41+
pinMode(BUTTON_LEFT, INPUT_PULLUP);
42+
pinMode(BUTTON_RIGHT, INPUT_PULLUP);
43+
pinMode(BUTTON_IN, INPUT_PULLUP);
44+
pixels.begin();
45+
pixels.setBrightness(30);
46+
pixels.show();
47+
}
48+
49+
50+
void loop(void) {
51+
// read encoder
52+
int curr_rotary = encoder.getPosition();
53+
RotaryEncoder::Direction direction = encoder.getDirection();
54+
55+
pixels.clear();
56+
if (curr_rotary != last_rotary) {
57+
Serial.print("Encoder value: ");
58+
Serial.print(curr_rotary);
59+
Serial.print(" direction: ");
60+
Serial.println((int)direction);
61+
}
62+
last_rotary = curr_rotary;
63+
64+
pixels.setPixelColor((curr_rotary + (1000*NUMPIXELS)) % NUMPIXELS, pixels.Color(0, 150, 0));
65+
66+
if (! digitalRead(BUTTON_UP)) {
67+
pixels.setPixelColor(0, pixels.Color(150, 0, 0));
68+
}
69+
if (! digitalRead(BUTTON_LEFT)) {
70+
pixels.setPixelColor(NUMPIXELS/4, pixels.Color(150, 0, 0));
71+
}
72+
if (! digitalRead(BUTTON_DOWN)) {
73+
pixels.setPixelColor(NUMPIXELS/2, pixels.Color(150, 0, 0));
74+
}
75+
if (! digitalRead(BUTTON_RIGHT)) {
76+
pixels.setPixelColor(NUMPIXELS*3/4, pixels.Color(150, 0, 0));
77+
}
78+
if (! digitalRead(BUTTON_IN)) {
79+
pixels.fill(pixels.Color(50, 50, 50));
80+
}
81+
pixels.show();
82+
83+
delay(20);
84+
}

library.deps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
depends=Adafruit ILI9341, Adafruit BusIO, SD, Adafruit NeoPixel, Adafruit VS1053 Library, Adafruit BluefruitLE nRF51, Adafruit seesaw Library, Ethernet, Adafruit IO Arduino, FastLED, Adafruit LiquidCrystal, Adafruit SoftServo, TinyWireM, Adafruit AM radio library, WaveHC, Adafruit LED Backpack Library, MAX31850 OneWire, Adafruit VC0706 Serial Camera Library, RTClib, Adafruit SleepyDog Library, Adafruit Thermal Printer Library, Adafruit Zero I2S Library, Adafruit EPD, Adafruit SSD1351 library, Adafruit FONA Library, Adafruit Motor Shield V2 Library, Adafruit NeoMatrix, Adafruit Soundboard library, Adafruit Circuit Playground, ArduinoJson, Adafruit TCS34725, Adafruit Pixie, Adafruit GPS Library, TinyGPS, WiFi101, Adafruit DotStar, Adafruit Si7021 Library, Adafruit WS2801 Library, Mouse, Keyboard, Time, IRremote, Adafruit LSM9DS0 Library, Adafruit Arcada Library, MIDIUSB, PubSubClient, Adafruit LIS2MDL, Adafruit NeoPXL8, Adafruit MCP23017 Arduino Library, Adafruit MLX90640, LiquidCrystal, Adafruit NeoTrellis M4 Library, RGB matrix Panel, Adafruit MLX90614 Library, Adafruit RGB LCD Shield Library, MAX6675 library, Adafruit MP3, Adafruit Keypad, Adafruit Arcada GifDecoder, Keypad, Neosegment, Encoder, Adafruit TiCoServo, Adafruit Trellis Library, FauxmoESP, Adafruit LSM303 Accel, Adafruit LSM303DLH Mag, CapacitiveSensor, Adafruit Zero PDM Library, Adafruit DMA neopixel library, elapsedMillis, DST RTC, Adafruit SHARP Memory Display, Adafruit SPIFlash, BSEC Software Library, WiiChuck, Adafruit DPS310, Adafruit AHTX0
1+
depends=Adafruit ILI9341, Adafruit BusIO, SD, Adafruit NeoPixel, Adafruit VS1053 Library, Adafruit BluefruitLE nRF51, Adafruit seesaw Library, Ethernet, Adafruit IO Arduino, FastLED, Adafruit LiquidCrystal, Adafruit SoftServo, TinyWireM, Adafruit AM radio library, WaveHC, Adafruit LED Backpack Library, MAX31850 OneWire, Adafruit VC0706 Serial Camera Library, RTClib, Adafruit SleepyDog Library, Adafruit Thermal Printer Library, Adafruit Zero I2S Library, Adafruit EPD, Adafruit SSD1351 library, Adafruit FONA Library, Adafruit Motor Shield V2 Library, Adafruit NeoMatrix, Adafruit Soundboard library, Adafruit Circuit Playground, ArduinoJson, Adafruit TCS34725, Adafruit Pixie, Adafruit GPS Library, TinyGPS, WiFi101, Adafruit DotStar, Adafruit Si7021 Library, Adafruit WS2801 Library, Mouse, Keyboard, Time, IRremote, Adafruit LSM9DS0 Library, Adafruit Arcada Library, MIDIUSB, PubSubClient, Adafruit LIS2MDL, Adafruit NeoPXL8, Adafruit MCP23017 Arduino Library, Adafruit MLX90640, LiquidCrystal, Adafruit NeoTrellis M4 Library, RGB matrix Panel, Adafruit MLX90614 Library, Adafruit RGB LCD Shield Library, MAX6675 library, Adafruit MP3, Adafruit Keypad, Adafruit Arcada GifDecoder, Keypad, Neosegment, Encoder, Adafruit TiCoServo, Adafruit Trellis Library, FauxmoESP, Adafruit LSM303 Accel, Adafruit LSM303DLH Mag, CapacitiveSensor, Adafruit Zero PDM Library, Adafruit DMA neopixel library, elapsedMillis, DST RTC, Adafruit SHARP Memory Display, Adafruit SPIFlash, BSEC Software Library, WiiChuck, Adafruit DPS310, Adafruit AHTX0, RotaryEncoder

0 commit comments

Comments
 (0)