Ive added a few extra line to my sketch today (146-178) and I am left with the message below, Ive been over and over it and cant see what Ive missing. It going to be something really obvious and simple, Its baking my head
nanocode1_buzzer.ino: In function 'void loop()':
nanocode1_buzzer:151: error: 'playBuzzer' was not declared in this scope
nanocode1_buzzer:158: error: a function-definition is not allowed here before '{' token
nanocode1_buzzer:287: error: expected }' at end of input nanocode1_buzzer:287: error: expected }' at end of input
/* Written by Venderbroeck. */
/*free to use, but a reference would be nice =) */
#include <LiquidCrystal.h>
//Setting up LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // set LCD interface pins
//transistor on pin 9
int speedsignal = 9;
//Piezo on pin 10
int piezo = 10;
//LED on pin 8
int egtled = 8;
//declaring storage array
int storage[60]; //megadataframe[60]
//declaring byteIn in which to temporarely store bytes recieved by
//the serial connection.
int byteIn = 0;
//declaring bools for header recognition script
bool checkheader1 = false;
bool checkheader2 = false;
//declaring trigger bool, used to trigger void loop script
bool trigger = false; //frametrigger
//counter for the loop filling the storage array with data from the MEGA
int i = 1;
//Declaring display value vars
int IATvalue = 0;
int EGTvalue = 0;
int AFRvalue = 0;
int BOOSTvalue = 0;
int SPEEDvalue = 0;
//BOOST/VAC
float rawval = 0; // Setup raw sensor value
float boost = 0; // Setup boost value
float vac = 0; // Setup vacuum value
//AFR
float rawvala = 0; // Setup raw afr sensor value
float afr = 0; // Setup value for afr value
//EGT
int rawvale = 0; // Setup raw egt sensor value
int egt = 0; // Setup value for egt value
//SPEED
int rawspeedval = 0; // Setup raw egt sensor value
int speedval = 0; // Setup value for egt value
void setup() {
{
pinMode(egtled, OUTPUT); //Define EGT high LED
pinMode(piezo, OUTPUT); //Define EGT high piezo
pinMode(speedsignal, OUTPUT); //Define speed signal switch
}
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
lcd.setCursor(4,0); //set cursor to top left corner
lcd.print("Volvo V70 R"); //print the text to the lcd
lcd.setCursor(3,2); //set cursor to top left corner
lcd.print("Custom tune by"); //print the text to the lcd
lcd.setCursor(5,3); //set cursor to top left corner
lcd.print("Avinitlarge"); //print the text to the lcd
{
delay(2000); //change the delay to change how fast the boot up screen changes
}
/*configuring lcd stuff*/
lcd.begin(20, 4); // set the LCD's columns and rows
// Setup static characters on the lcd
lcd.setCursor(2,0);
lcd.print("IAT:");
lcd.setCursor(2,1);
lcd.print("EGT:");
lcd.setCursor(2,2);
lcd.print("AFR:");
lcd.setCursor(0,3);
lcd.print("BOOST:");
Serial.begin(9600);
}
void loop() {
if (trigger == true) {
IATvalue = storage[1];
EGTvalue = storage[2];
AFRvalue = storage[3];
BOOSTvalue = storage[4];
SPEEDvalue = storage[5];
/*add code here to values to lcd*/
//IAT Gauge start
lcd.setCursor(7,0);
lcd.print(IATvalue,1); // Prints the IAT figure
lcd.print((char)178);
lcd.print("C ");
//IAT Gauge end
//Speed Gauge start
// some base calculations to get speed
rawspeedval = (SPEEDvalue); // Calculate speed value from raw value for debugging
speedval = (rawspeedval*(0.621371)); // Calculate afr from raw value ***(calculations need proving)***
// lcd.setCursor(7,2);
// lcd.print(afr,1); // Prints the speed figure
//AFR Gauge end
if (speedval < 15) // set for temp for LED to switch on
{
digitalWrite(speedsignal, HIGH);
}
else
{
digitalWrite(speedsignal, LOW);
}
//Speed Gauge end
//EGT Gauge start
rawvale = (EGTvalue); // Calculate afr value from raw value for debugging
egt = (rawvale*(4)); // Calculate afr from raw value ***(calculations need proving)***
lcd.setCursor(7,1);
lcd.print(egt,1); // Prints the EGT figure
lcd.print((char)178);
lcd.print("C ");
//EGT Gauge end
//EGT LED warning start
// if (egt > 800) // set for temp for LED to switch on
// {
// digitalWrite(egtled, HIGH);
// }
// else
// {
// digitalWrite(egtled, LOW);
// }
//EGT LED warning end
//EGT piezo warning start
if(egt > 800)
{
// sound buzzer
playBuzzer(piezo);
}
delay(100);
}
void playBuzzer(int piezo)
{
for(int i = 0; i < 3; ++i)
{
// alternate between two tones, one high and one low
// at the same time alternate the blue and red LED flashing
digitalWrite(egtled, HIGH); // LED on
tone(piezo, 400); // play 400 Hz tone for 500 ms
delay(500);
digitalWrite(egtled, LOW); // LED off
digitalWrite(egtled, HIGH); // LED on
tone(piezo, 800); // play 800Hz tone for 500ms
delay(500);
digitalWrite(egtled, LOW); // LED off
}
// Stop the buzzer
noTone(piezo);
}
//EGT piezo warning end
//AFR Gauge start
// some base calculations to get afr
rawvala = (AFRvalue); // Calculate afr value from raw value for debugging
afr = (rawvala*(0.03671875)+10); // Calculate afr from raw value ***(calculations need proving)***
lcd.setCursor(7,2);
lcd.print(afr,1); // Prints the afr figure
//AFR Gauge end
//Boost gauge start
// some base calculations to get pressures
rawval = (BOOSTvalue); // Read MAP sensor raw value on analog port 0
//kpaval = (rawval*(0.004)/(0.022)+20); // Calculate kpa value from raw value for debugging
boost = ((((rawval/255) + 0.04)/0.004)*0.145) - 14.528; // Calculate psi from raw value ***(calculations need proving)***
if (boost >= 0) // Set condition for bargraph to show above zero (negative numbers cause LCD crash)
{
lcd.setCursor(7,3);
lcd.print(boost,1); // Prints the BOOST figure
lcd.setCursor(11,3);
lcd.print("psi "); // Prints 'psi' with a space after it to clear the 'g' off 'inHg'
}
if (boost < 0)
{
lcd.setCursor(7,3);
lcd.print(vac,1); // Prints the vacuum figure
vac = boost*-2.036025; // Used 'minus' 2.036025 so that the figure printed wont have a minus symbol in front of it
lcd.setCursor(11,3);
lcd.print("inHg"); // Changes the units to 'inHg' on the lcd
}
//BOOST Gauge end
/**/
trigger = false;
}
}
void serialEvent() {
//Run the while loop for as long as serial data is available.
//Keep in mind the whole loop will iterate once for each incoming byte.
while (Serial.available() ) {
//reset byteIn variable. Might be redundant.
byteIn = 0;
//take byte out of the serial 3 buffer and store it.
byteIn = Serial.read();
/*the next if statements need to be ran in this specific order.
They look for the header and store the MEGA dataframe in 'storage' for
later use by the nano.
MEGA header = 5F AF
MEGA footer = B4 64 */
//If both the headerbytes have been recieved and i == 5,
//the loop storing the body has allready been completed, so
//both checkheader triggers reset to false and i resets to 1
//Also it will set the void loop trigger to true to run the script it contains.
if (checkheader1 == true && checkheader2 == true && i == 5) {
checkheader1 = false;
checkheader2 = false;
trigger = true;
i = 1;
}
//ERRORCHECK
//If first headerbyte was recieved, and the second was not,
//and the byte stored isn't AF, something went
//wrong and checkheader1, and i both reset.
if (checkheader1 == true && checkheader2 == false && byteIn != 0xAF) {
checkheader1 = false;
i = 1;
}
/*The actual part filling the array. Everytime the while(serial available())
loop iterates, and the headertriggers are set true, and nothing was changed
above this will write the byte stored in byteIn to the proper place in storage.
Note that i is incremented here each iteration. When it reaches 5 (all bytes recieved)
all triggers, including i are reset above in the next loop iteration. */
if(checkheader1 == true && checkheader2 == true) {
storage[i] = byteIn;
i++;
}
//if byteIn contains the first headerbyte, checkheader1 is set to true
if (checkheader1 == false && byteIn == 0x5F) {
checkheader1 = true;
}
//if the first headerbyte has been received, and byteIn contains the
//second headerbyte, checkheader 2 is set to true
if(checkheader1 == true && byteIn == 0xAF) {
checkheader2 = true;
}
//end of while serial.available loop
}
//end of void serial.event
}