Advertisement
Guest User

Untitled

a guest
May 17th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #define dataPin 2
  2. #define outPin 6
  3. void setup()
  4. {
  5. DDRD |= (1<<outPin); //set the pin (6) to be an output... when pin 6 is an output PORTD controlls whether it's high or low with 1 or 0
  6. DDRD &= ~(1<<dataPin); //Set controllerDataPin (pin 4) to be an input
  7. PORTD |= (1<<dataPin); //Set controllerDataPin (pin 4) to have a pullup resistor enabled
  8. attachInterrupt(digitalPinToInterrupt(dataPin), falling_edge, FALLING); //attach interrupt function
  9. }
  10.  
  11. void loop()
  12. {
  13. //empty
  14. }
  15.  
  16. void falling_edge()
  17. {
  18. delayMicroseconds(2); //delay 2 microseconds
  19. PIND&(1<<dataPin)? //if you read a high on Pin 4
  20. PORTD|=(1<<outPin): //set pin 6 high
  21. PORTD&=~(1<<outPin); //otherwise set pin 6 low
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement