Hi Guys n Girls,
I am a newbie and have been programming for a couple of months. I have had success putting all of my software in the loop but am having alot of difficulty understanding functions (void myfunction()). I have gone thru alot of tutorials but they don't cover this much.
Can someone tell me why the attached code does not work as a function ? (it does work inside the loop).
I am trying to write a whole bunch of sub-routines so my loop is easier to follow and not so crowded.
Thanks
void setup ()
{
lcd.begin(16,2); // intiallises the LCD display and defines the size (16 Characters, 2 Lines).
pinMode(Relay, OUTPUT); // Sets the Relay on Pin 8 to an OUTPUT.
pinMode(AuxRelay, OUTPUT); // Sets the AuxRelay on Pin 7 to an OUTPUT.
Serial.begin(9600); // Intialilises the Serial display for testing purposes.
}
// Main Program - This will run thru continously until power is disconnected or reset button is pressed.
void loop()
{
TurnMeOn;
delay(50); // Delay for LCD display
}
void TurnMeOn(){
// Check the state of the Ignition and turn off backlight if off or PWM backlight and display company details.
int Power = analogRead(A4); // Check the state of the ignition pin and store the result in "power".
Serial.print(LDR); // Serial Monitor for testing purposes only
Serial.println(Power); // As above
// Igniton is on - Control intensity of Backlight by reading the LDR and PWMing the Backlight.
if (Power > 700 && LastState == HIGH) // Checks to see if the Ignition is on by looking for more then 700 DAC counts
{ // Also checks Last State is HIGH (It has already displayed company logo.
LDR = analogRead(A5); // reads the DAC Counts from Analog 5 and stores the result in LDR.
analogWrite(BackLight, LDR / 2); // PWM's the backlight between 0 & 255.
lcd.setCursor(0,0); // Sets the Cursor to Position 1, Line 1.
lcd.print("section else if"); // Prints to LCD
// Ignition has just been switched ON from the OFF state, We want to throw in a little advertising.
if ( Power > 700 && LastState == LOW )
{
analogWrite(BackLight, 200); // Sets the Backlight to 3/4 brightness for logo only.
lcd.clear(); // Clears the LCD display.
lcd.print(" BLACKSNAKE SYS "); // Prints whats in the brackets on the LCD display.
// Spaces 1234567890123456 , this is just to make sure we are using the correct number of characters available on the LCD.
lcd.setCursor(0,1); // Sets the cursor the the first position on line 2. (Character, Line (16,2)).
lcd.print("DBC MARK 4, Ver1"); // prints to LCD.
LastState = HIGH; // Stops this from occuring every loop.
delay(2000); // Delay's for 2 seconds whilst company logo is being displayed.
lcd.clear(); // Clears the display.
// If the ignition is switched off we will turn the backlight off to reduce theft factor.
if ( Power < 500 ) // Checks that the ignition is below 500 DAC counts.
{
analogWrite(BackLight, 0); // Sets the Backlight PWM to 0 (OFF)
LastState = LOW; // Sets state to LOW so logo is written when ignition is turned back on
}}}}
I have tried it with the"{ }" as one set only and also 3 sets.