I am making a program to use a rotary encoder instead of a button in the buttoncycler example in the Adafruit NeoPixel library.
I am using the US Digital S1-256-250-IE-B-D. Datasheet can be found here:
https://cdn.usdigital.com/assets/datasheets/S1_datasheet.pdf?k=636466553771569761
#include < RotaryEncoder.h >
void setup() {
}
void loop() {
static int change = 0;
static int pos = 0;
static int oldPos = 0;
//Read the Encoder's state
encoder.tick();
int enc = encoder.getPosition();
pos = abs(enc) % 2;
change = oldPos-pos;
if (change != 0) {
switch (pos) {
case 0:
//do a program that lasts 5 seconds
break;
case 1:
//do a program that lasts 5 seconds
break;
}
oldPos = pos;
change = 0;
}
}
I was wondering if there is a way to change the program immediately after turning the rotary encoder, instead of having to wait for the program to complete.
Setup()
is missing.i
is not defined. – Code Gorilla Nov 23 '17 at 13:39