Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
It's been a very long time that I played with a rotary switch, but I think the biggest, and I've never used the Rotary library (I've found a few, but I'm assuming it is this rotary lib?), so I'm not sure what I'm even looking at.
Pins 2 and 3 seem a good choice since most common Arduino's support these 2 pins for attaching an interrupt to.
When looking at this example code for rotary.h; I see no purpose of A0?
/*
Rotary Encoder - Interrupt Example
The circuit:
* encoder pin A to Arduino pin 2
* encoder pin B to Arduino pin 3
* encoder ground pin to ground (GND)
*/
#include <Rotary.h>
Rotary r = Rotary(2, 3);
void setup() {
Serial.begin(9600);
r.begin();
PCICR |= (1 << PCIE2);
PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
sei();
}
void loop() {
}
ISR(PCINT2_vect) {
unsigned char result = r.process();
if (result == DIR_NONE) {
// do nothing
}
else if (result == DIR_CW) {
Serial.println("ClockWise");
}
else if (result == DIR_CCW) {
Serial.println("CounterClockWise");
}
}
With limited info and zero experience with the rotary library, I can only throw out some random thoughts.
From the rotary lib documentation, I assumed the rotary lib would already handle the interrupts. I could be very wrong though.
Next, you say it works on an Arduino Uno (assuming this is what you mean with Arduino 1???) but not on the mega it does not. Does the rotary example code for interrupts work? (the one I just posted - copied from the rotary library documentation)
Oh cool! Good to know 👍🏻 Also thank you for posting the hint where to look -- others will benefit from it I'm sure.
Just being curious though; did you run the test on the Uno and the Mega? And both worked? Just wondering if the additional "A0" causes and unexpected problem on the Mega - It's not part of the rotary, right?
The call to the Rotary function accepts 3 arguments, the first two being the interrupt pins coming from the encoder and the third the pressed button present in the mechanical encoder.
// Initialize the Rotary object
// Rotary(Encoder Pin 1, Encoder Pin 2, Button Pin)
Rotary r = Rotary(2, 3, A0);
Frizting Free tool to design schematics and PCB's - they even offer a very affordable PCB production service.
Leapfrog 3D printers Manufacturer of the great Creatr and Xeed 3D printers - Stunning customer service!!
Visualping Great website if you like to track website changes when changes occur (hourly, daily, weekly).
Ulvenhout.com My home town ... Ulvenhout in the Netherlands (Noord Brabant)
Photopea A free alternative to Photoshop (pretty close anyway), and runs in your browser - this works surprisingly good!
XKPassword Super practical website for those who need to generate one or a list of passwords based on words (more secure).
Links Page These and more of our favorite links can be found on the Links Page.
New Downloads
ConnectMeNow4-v4.0.18-macOS-x86-64.dmgDate: 2024-04-24 - Size: 3.5 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Intel version which works on Intel and Apple Silicon Macs.
ConnectMeNow4-v4.0.18-macOS-arm64.dmgDate: 2024-04-24 - Size: 3 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Apple Silicon version (not suitable for Intel).
MiniWOL2 MacOS (64 bits Apple Silicon)Date: 2023-08-01 - Size: 1.2 MBminiWol is a simple, but effective application to send Wake On LAN to network devices. This is the signed 64 bit MacOS ARM (Apple Silicon) version.
MovieScanner2-2.2.3-Windows-32bit-setup.exeDate: 2023-04-12 - Size: 18.6 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 32 bit Windows version.
MovieScanner2-2.2.2-Linux-GTK-64bits.tar.gzDate: 2023-04-11 - Size: 29.2 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for GTK.
MovieScanner2-2.2.2-Linux-QT5-64bits.tar.gzDate: 2023-04-11 - Size: 29.1 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for QT5.
Downloads Page Find these and more Downloads on the Downloads Page, where you will also find articles references, operating system requirements and categories.
Amazon Ads
Support us by doing your shopping at Amazon.com, either click the link, or click one of the links below …
You can also sponsor us through these Amazon offerings:
Please consider disabling your ad blocker for our website.We rely on these ads to be able to run our website.You can of course support us in other ways (see Support Us on the left).