Advertisement
Zaganu

encoder test- working /a uno

May 27th, 2020
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. int encoder_position = 0;
  4. int pozitie_motor = 0;
  5.  
  6. void setup() {
  7.   Serial.begin(9600);
  8.   DDRD = DDRD | B00000000;  // this is safer as it sets pins 2 to 7 as outputs
  9.   attachInterrupt(digitalPinToInterrupt(3), encoder, RISING);
  10.   //detachInterrupt(digitalPinToInterrupt(3))
  11. }
  12.  
  13. void automat()
  14. {
  15.   // state  10 { pozite motor = 1200;
  16. }
  17.  
  18. void loop() {
  19.   // put your main code here, to run repeatedly:
  20.   Serial.println(encoder_position);
  21. }
  22.  
  23. void encoder()
  24. {
  25.   if ((PIND & B00000100) == 4)
  26.   {
  27.     encoder_position++;
  28.   }
  29.   else
  30.   {
  31.     encoder_position--;
  32.   }
  33.   if (encoder_positon == pozitie_motor)
  34.   {
  35.     // stop releu
  36.   }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement