Created
October 27, 2017 19:09
-
-
Save abezukor/3a2b47760190242eae85247183e0424a to your computer and use it in GitHub Desktop.
A simple program for the Arduino that converts a 10hz input to a 60hz output.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//sets the input pin to pin 4 | |
int inputpin = 4; | |
//sets the outputpin to pin 2 | |
int outputpin = 2; | |
//sets the base time between pulses based on 60Hz | |
float betweenpulses = (100.0/6.0)*1000; | |
//claculates how long the uptime is | |
float uptime = 0.1*betweenpulses; | |
//claculates how long the downtime is | |
float downtime = betweenpulses-uptime; | |
void setup() { | |
// put your setup code here, to run once: | |
//sets the input pin | |
pinMode(inputpin, INPUT); | |
//sets the output pin | |
pinMode(outputpin, OUTPUT); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
//reads the status of the inputpin | |
int inputstate = digitalRead(inputpin); | |
//if there is a signal in the input pin | |
if (inputstate == HIGH){ | |
//delay after the input pulse | |
delay(0); | |
//makes 5 pulses that have the uptime and downtime specified earlier | |
for (int loopnumber = 0; loopnumber<5; loopnumber++){ | |
digitalWrite(outputpin, HIGH); | |
delayMicroseconds(uptime); | |
digitalWrite(outputpin, LOW); | |
delayMicroseconds(downtime); | |
} | |
//makes the 6th pulse except does not give delay after it turn the output pin off | |
digitalWrite(outputpin, HIGH); | |
delayMicroseconds(uptime); | |
digitalWrite(outputpin, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment