- #1
Weightofananvil
- 34
- 1
Hi Everyone,
I'm coding an circuit in arduino that reads a sensor to gauge a motors RPM.
I have the arduino reading the speed and blinking an LED. Now I need some way of taking that data
reading it for say half a second, perform calculations to double the count (to make it per minute)
send the data and then clear the variable but I can't think of how to do that since C code
is sequencial...
Im more looking for logical answers then someone to spit me out some code...
Im starting to think Just make 2 variables... and make them alternate "turns" of counting
then the one's loop will clear the others variable...
any suggestions?
Thanks
int count = 0;
const int encoderIn = 8; // input pin for the interrupter
const int statusLED = 13; // Output pin for Status indicator
const int pulseOutput = 12; // Pulse output pin for external interfacing
int detectState=0; // Variable for reading the encoder status
void setup()
{
pinMode(encoderIn , INPUT); //Set pin 8 as input
pinMode(statusLED, OUTPUT); //Set pin 13 as output
pinMode(pulseOutput, OUTPUT); // Set Pin 12 as output
}
void loop() {
detectState=digitalRead(encoderIn);
if (detectState == HIGH) { //If encoder output is high
digitalWrite(statusLED, HIGH); //Turn on the status LED
digitalWrite(pulseOutput,HIGH); // Give a logic-High level output
}
else {
digitalWrite(statusLED, LOW); //Turn off the status LED
digitalWrite(pulseOutput,LOW); // Give a logic-Low level output
}
}
I'm coding an circuit in arduino that reads a sensor to gauge a motors RPM.
I have the arduino reading the speed and blinking an LED. Now I need some way of taking that data
reading it for say half a second, perform calculations to double the count (to make it per minute)
send the data and then clear the variable but I can't think of how to do that since C code
is sequencial...
Im more looking for logical answers then someone to spit me out some code...
Im starting to think Just make 2 variables... and make them alternate "turns" of counting
then the one's loop will clear the others variable...
any suggestions?
Thanks
int count = 0;
const int encoderIn = 8; // input pin for the interrupter
const int statusLED = 13; // Output pin for Status indicator
const int pulseOutput = 12; // Pulse output pin for external interfacing
int detectState=0; // Variable for reading the encoder status
void setup()
{
pinMode(encoderIn , INPUT); //Set pin 8 as input
pinMode(statusLED, OUTPUT); //Set pin 13 as output
pinMode(pulseOutput, OUTPUT); // Set Pin 12 as output
}
void loop() {
detectState=digitalRead(encoderIn);
if (detectState == HIGH) { //If encoder output is high
digitalWrite(statusLED, HIGH); //Turn on the status LED
digitalWrite(pulseOutput,HIGH); // Give a logic-High level output
}
else {
digitalWrite(statusLED, LOW); //Turn off the status LED
digitalWrite(pulseOutput,LOW); // Give a logic-Low level output
}
}