Writing some code to get the hang of things. Got this error during the compile. Can't figure it out, seems like I have all my parenthesis in the right places. Probably something to do with my lack of understanding C++. Here's the code.
#include <Wire.h>
//Variables
volatile byte rpmcount = 0;
unsigned long rpm = 0;
unsigned long timeold = 0;
int analog_rpm = 0;
int potPin = 1;
int potVal;
unsigned long rpm_max = 0;
void setup()
{
attachInterrupt(0, RPM_Func, FALLING); //Setup interrupt on pin 2 and set the pull-up resistor on
digitalWrite(2, HIGH);
Wire.begin(); //Join I2C bus (address optional for master)
}
void loop()
{
potVal = analogRead(potPin); //Read the maximum RPM pot value, this will be used later for scaling
rpm_max = map(potVal, 0, 1023, 3500, 10000);
if (rpmcount >= 5) { //If there are more than 5 counts, calculate the RPM
rpm = (((rpmcount * 1000000) / (micros() - timeold))) * 60;
timeold = micros();
analog_rpm = map(rpm, 0, potVal, 0, 255); //Map the RPM to an analog value based on the earlier value read from
writeI2C(analog_rpm); //the potPin and output it to the I2C buffer
rpmcount = 0; //Reset the count
}
else {
analog_rpm = 0; //If there are less than five counts, tell the I2C buffer that RPM
writeI2C(analog_rpm); //is zero
}
}
void writeI2C(int val) //Function to write values to the DAC I2C buffer
{
const int I2C_address = 0x98; //Write address of I2C DAC
Wire.beginTransmission(I2C_address);
Wire.send(val);
Wire.endTransmission;
}
void RPM_Func() //Function used by the interupt to increment the rpm counter
{
rpmcount++;
}
Any help would be appreciated,
Thanks.
-Ian