Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simple sketch to read the pulse width of a PWM signal
- // Useful for reading PWM valuss from a R/C reciever
- // to create actions that are not typically handled
- // with a servo, such as controlling LED lighting.
- int pin = 8; // Check what pin to use
- int output = 1; // pin to blink
- int duration; // Duration of the pulse
- // setup serial and input, output pins
- void setup()
- {
- Serial.begin(9600);
- pinMode(pin, INPUT); // PWM input pin
- pinMode(output, OUTPUT); // Output Pin
- }
- void loop()
- {
- duration = pulseIn(pin, HIGH);
- if (duration > 150)
- {
- digitalWrite(output, HIGH);
- }
- else
- {
- digitalWrite(output, LOW);
- }
- Serial.print("Flow Value: ");
- Serial.println(duration);
- delay(100); //delay so you can read the scrolling output
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement