Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A 10hz to 60 hz converter for the ardueno. read more at... to post
//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