Advertisement
Guest User

Arduino Flow

a guest
Feb 22nd, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. // Simple sketch to read the pulse width of a PWM signal
  2. // Useful for reading PWM valuss from a R/C reciever
  3. // to create actions that are not typically handled
  4. // with a servo, such as controlling LED lighting.
  5.  
  6. int pin = 8; // Check what pin to use
  7. int output = 1; // pin to blink
  8. int duration; // Duration of the pulse
  9.  
  10. // setup serial and input, output pins
  11. void setup()
  12. {
  13.  
  14. Serial.begin(9600);
  15. pinMode(pin, INPUT); // PWM input pin
  16. pinMode(output, OUTPUT); // Output Pin
  17.  
  18. }
  19.  
  20. void loop()
  21. {
  22.  
  23. duration = pulseIn(pin, HIGH);
  24. if (duration > 150)
  25. {
  26. digitalWrite(output, HIGH);
  27. }
  28. else
  29. {
  30. digitalWrite(output, LOW);
  31. }
  32. Serial.print("Flow Value: ");
  33. Serial.println(duration);
  34.  
  35. delay(100); //delay so you can read the scrolling output
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement