ok I got a button push counter integrated into the sketch. It now triggers pin 13 (an LED / event) when the button is pushed 4 times (very slowly :~ got to figure that out also ). I also think i've got 'most' of an integer variable setup right for each of the sensors but I think I'm missing a little bit.
Basically I need the LED / event to trigger switching to the next menu item and when it comes to the end, it goes to the beginning. Tie the event (LED high) to switch to one of the sensorVar (I think)
Here's my code as it sits now. Of course I'm open to all suggestions.
#include <LiquidCrystal.h> // include the LCD library
#include <LcdBarGraph.h> // include the LCDBarGraph library
// DISPLAY VARS (setup for the LCD display, ran on startup once)
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
byte lcdNumCols = 16; // -- number of columns in the LCD
LcdBarGraph lbg(&lcd, lcdNumCols); // -- creating
// SENSOR VARS (Telling the Arduino ports which to activate, ran once on startup)
const int buttonPin = 5; // the pin that the wheel switch is attached to
const int ledPin = 13; // the pin that the LED is attached to
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int sensorPin0 = 0; // -- value for this example
int sensorPin1 = 1; // -- value for this example
int sensorPin2 = 2; // -- value for this example
int val = 0; // variable for reading the pin 0 status
// float maxVoltage = 4.65; // Maximum voltage sent out from the sensors (these values are the same for O&F not for B)(For a later time)
// float minVoltage = .46; // Minimum voltage sent out from the sensors (these values are the same for O&F not for B)(For a later time)
// float scale = 4.5/1024.0; // convert 10-bit value to 4.5v scale for sensor (will need this for scaleing the sensor)(For a later time)
// float Oil ; ???
// float fuel ; ???
// float Boost ; ???
int sensorVal0 = 0;
int sensorVal1 = 1;
int sensorVal2 = 2;
void setup() // (setup and starting the activated Arduino ports, runs once)
{
{
// OIL PRESSURE SENDER SETUP
lcd.begin(16, 2); // lcd rows and columns
lcd.setCursor(0, 1); // set cursor to second row, first column
lcd.print("Oil Pressure"); // title of sorts
sensorVal0 = analogRead(sensorPin0); // read Analog0 pin sensor oil and mapping it to a value
delay(500); // ~ 2Hz display is fast enough
}
{
// FUEL PRESSURE SENDER SETUP
lcd.begin(16, 2); // lcd rows and columns
lcd.setCursor(0, 1); // set cursor to second row, first column
lcd.print("Fuel Pressure"); // title of sorts
sensorVal1 = analogRead(sensorPin1); // read Analog1 pin sensor fuel and mapping it to a value
delay(500); // ~ 2Hz display is fast enough
}
{
// BOOST PRESSURE SENDER SETUP
lcd.begin(16, 2); // lcd rows and columns
lcd.setCursor(0, 1); // set cursor to second row, first column
lcd.print("Boost"); // title of sorts
sensorVal2 = analogRead(sensorPin2); // read Analog1 pin sensor fuel and mapping it to a value
delay(500); // ~ 2Hz display is fast enough
}
// lcd.begin(16, 2); // lcd rows and columns (will be removed once switching is resolved)
// lcd.setCursor(0, 1); // set cursor to second row, first column (will be removed once switching is resolved)
// lcd.print("XYZ oil 0"); // title of sorts (will be removed once switching is resolved)
// delay(500); // time to display title (will be removed once switching is resolved)
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop() // (stuff that is constantly looped or monitored)
{
// BUTTON COUNTS
buttonState = digitalRead(buttonPin); // read the pushbutton input pin:
if (buttonState != lastButtonState) { // compare the buttonState to its previous state
if (buttonState == HIGH) { // if the state has changed, increment the counter
// if the current state is HIGH then the button
// went from off to on:
buttonPushCounter++;
// Serial.println("on");
// Serial.print("number of button pushes: ");
// Serial.println(buttonPushCounter, DEC);
// }
// else {
// if the current state is LOW then the button
// went from on to off:
// Serial.println("off");
}
}
lastButtonState = buttonState; // save the current state as the last state, for next time through the loop
if (buttonPushCounter % 4 == 0) { // turns on the LED every four button pushes by
digitalWrite(ledPin, HIGH); // checking the modulo of the button push counter.
} else { // the modulo function gives you the remainder of
digitalWrite(ledPin, LOW); // the division of two numbers:
}
{
// sensorVal0 = analogRead(sensorPin0); // read Analog0 pin sensor oil and mapping it to a value
// sensorVal1 = analogRead(sensorPin1); // read Analog1 pin sensor fuel and mapping it to a value
// sensorVal2 = analogRead(sensorPin2); // read Analog2 pin sensor boost and mapping it to a value
}
// BAR GRAPH RESULTS FOR EACH SENSOR
{
lbg.drawValue( analogRead(sensorPin0), 1024); // -- Analog 0 sensor pin for Oil sender, link for the LCDBarGraph library)
delay(500); // ~ 2Hz display is fast enough
}
{
lbg.drawValue( analogRead(sensorPin1), 1024); // -- Analog 1 sensor pin for Fuel sender, link for the LCDBarGraph library)
delay(500); // ~ 2Hz display is fast enough
}
{
lbg.drawValue( analogRead(sensorPin2), 1024); // -- Analog 2 sensor pin for Boost MAP sender, link for the LCDBarGraph library)
delay(500); // ~ 2Hz display is fast enough
}
}