Forum / Guestbook




Luberth Tue 19 Mar 2019 at 8:33:48
Arduino Encoder Example

-
Arduino Encoder Example

A Arduino Enconder test for my arduino automatic chicken coop door
http://84.106.2.21:8888/forum/index.php?action=view&id=255


red=+5vdc red
black=0vdc ground blue
white=pin 2 int white
green=pin 3 int green

original example was unsigned count i make it signed for negative below 0
maybe signed long is better as signed int, now after 32767 it counts down again
unsigned int 0 to 65,535
signed int -32,768 to 32,767
signed long from -2,147,483,648 to 2,147,483,647

//I recieved an Encoder today, a BirthDay present from my Friends from China
//and it works in notime, Arduino is Great, this encoder using looked so difficult for me in the past

//https://github.com/jumejume1/Arduino/blob/master/ROTARY_ENCODER/ROTARY_ENCODER.ino
//Please Donate To Help Me Afford New Equipment And Software To Make My Videos More : 
//http://84.106.2.21:8888/forum/index.php?action=view&id=261
//http://84.106.2.21:8888/forum/index.php?action=view&id=255


Nobody out there that wants to buy a Cup of Coffee for me ;-(
its 19 march when i wrote this, This day 51 years ago i entered this world,
But Sorry i am not giving koffie and pie to all of you out there ;-)

// my encoder = LDP3806-360BM-G5-24C // IT GIVES 720 COUNTS PER REVOLUTION // https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20190319001228&SearchText=Incremental+Optical+Rotary+Encoder // arduino code example encoder // red= +5vdc red // black= 0vdc, ground blue // white= pin 2 interrupt white // green= pin 3 interrupt green // original example was unsigned from 0 in negative direction to 65thousand something => signed from 0 to negative =-1 volatile signed int temp, counter = 0; //This variable will increase or decrease depending on the rotation of encoder void setup() { Serial.begin (9600); pinMode(2, INPUT_PULLUP); // internal pullup input pin 2 pinMode(3, INPUT_PULLUP); // internalเป็น pullup input pin 3 //Setting up interrupt //A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on moust Arduino. attachInterrupt(0, ai0, RISING); //B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on moust Arduino. attachInterrupt(1, ai1, RISING); } void loop() { // Send the value of counter if( counter != temp ){ Serial.println (counter); temp = counter; } } void ai0() { // ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH // Check pin 3 to determine the direction if(digitalRead(3)==LOW) { counter++; }else{ counter--; } } void ai1() { // ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH // Check with pin 2 to determine the direction if(digitalRead(2)==LOW) { counter--; }else{ counter++; } } // https://github.com/jumejume1/Arduino/blob/master/ROTARY_ENCODER/ROTARY_ENCODER.ino // http://84.106.2.21:8888/forum/index.php?action=view&id=261 // http://84.106.2.21:8888/forum/index.php?action=view&id=255









A Arduino Enconder test for my arduino automatic chicken coop door
http://84.106.2.21:8888/forum/index.php?action=view&id=255






now i want to do something like this









End of Message, Thanks For Viewing! ☺
Tip: if your watching on your phone or tablet ⁝ add / save to homescreen and you get a nice icon its Free!
Tip: on your computer or laptop do not forget to bookmark this page its Free!
BookMark ShortCut Keys press ctrl+d on your keyboard




-

-

Reply to this Message


Name
Subject
Message

, <code> <b> <i> <u> .






POLL / VOTE
Did you like this Page id=261 ?

NO:         YES:




   


Design a Bit like ForumOne 4.0 WayBack 1999 ©
Always Read the Small print?!



http://forum.luberth.com - - http://www.luberth.com/forum/

NO COOKIES !?

thanks for your support
Thank You!




Co2 FootPrint WebServer



                         My Cheap Chinese Friend Ali     
Copyright Luberth Dijkman 2018 ... 2019