I'm trying to use a rotary encoder with a 5V trinket to make a neopixel jewel change color when its turned, then when I press a button the rotary encoder will change brightness instead.
I just can't wrap my head around any of the programming.
I was trying to use this guide at first but I just cant get anything to work. Probably because its originally meant for a potentiometer.
If anyone can help with this it would be greatly appreciated!
The first thing to do is to read the encoder and get sensible output from it that you can then use to control the program. Have you managed to do that ?
Please post a link to the rotary encoder that you are using
UKHeliBob:
The first thing to do is to read the encoder and get sensible output from it that you can then use to control the program. Have you managed to do that ?
Please post a link to the rotary encoder that you are using
I actually have no idea how to read the encoder so I haven't been able to do that.
I pulled the rotary encoder off an old radio so I don't have much information on it.
Here is some simple code to reat a rotary encoder and identify which direction it is turning in
const byte channelA = 7; //encoder outputs connected to these pins
const byte channelB = 8;
byte currentStateA = HIGH;
byte previousStateA = HIGH;
byte currentStateB = HIGH;
byte previousStateB = HIGH;
void setup()
{
Serial.begin(115200);
pinMode(channelA, INPUT);
pinMode(channelB, INPUT);
}
void loop()
{
previousStateA = currentStateA;
currentStateA = digitalRead(channelA);
previousStateB = currentStateB;
currentStateB = digitalRead(channelB);
if (currentStateA != previousStateA && currentStateA == LOW)
{
if (currentStateB == LOW)
{
Serial.println("forwards\n");
}
}
if (currentStateB != previousStateB && currentStateB == LOW)
{
if (currentStateA == LOW)
{
Serial.println("reverse\n");
}
}
}
UKHeliBob:
Here is some simple code to reat a rotary encoder and identify which direction it is turning in
It took me a while to figure out why I kept getting a serial error. Turns out It wouldn't work on a Trinket.
I gave it a shot on a Trinket Pro I'm using for another project, but I'm not having anything show up on the serial monitor.
MorganTA:
I actually have no idea how to read the encoder so I haven't been able to do that.
Have you been here yet? Or here?
Those are the first two google (hint hint) hits for "Arduino encoder"