Hi guys,
So I've got a program where I communicate to my arduino via serial from a windows form C# app on my pc.
I'm trying to pickup rpm (hall effect) and temperature (voltage) from sensor. Code would look something like this:
int message = 0; // This will hold one byte of the serial message
int ledPin = 13; // This is the pin that the led is conected to
//int LED = 0; // The value or brightness of the LED, can be 0-255
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
int rpmPin = 12;
void setup()
{
pinMode(rpmPin, OUTPUT);
Serial.begin(9600); //set serial to 9600 baud rate
pinMode(ledPin, OUTPUT);
attachInterrupt(0, rpm_fun, RISING);
rpmcount = 0;
rpm = 0;
timeold = 0;
}
void loop()
{
digitalWrite(rpmPin, HIGH);
delay(100);
digitalWrite(rpmPin, LOW);
delay(100);
if (Serial.available() > 0)
{
message = Serial.read();
if (message == 'A')
{
digitalWrite(ledPin, HIGH);
Serial.println("LED on");
}
if (message == 'a')
{
digitalWrite(ledPin, LOW);
Serial.println("LED off");
}
if (message = 's')
{
{
if (rpmcount >= 2)
{
//Update RPM every 20 counts, increase this for better RPM resolution,
//decrease for faster update
rpm = 30*1000/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
Serial.println(rpm,DEC);
}
}
}
}
}
void rpm_fun()
{
rpmcount++;
//Each rotation, this interrupt function is run twice
}
I get stuck in the the rpm function. Is this a limitation of the arduino or should I be able to serial input commands and read values (via serial) from different pins while running an interrupt?
Thanks in advance.
To add more clarity. I would like to send a command to run function to stream rpm ('s') then change functions for temp ('t')then stream that pin. Is this possible?
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.