Hello folks,
Brand spanking new to arduino, and coding of any kind.
I've had decent luck so far, combining two sketches, and using a pot. switch in place of other sensors for the time being, while I get familiar with the coding, and set up the way I'd like.
The first sketch used a pot. switch to control 3 LED's. The second sketch showed a pot. switches value as a percentage on the 16x2 display.
For each of the four sensors I'd like to eventually monitor, I played with the text and pot. values a little bit, and saved as a separate sketch.
Basically, I'd like to be able to push a button, and display each one. Seems fairly basic, but I can't seem to find the solution, and feel kinda stalled.
Could anyone help me out?
Thanks
/* YourDuinoStarter Example: Sketch Template
- WHAT IT DOES
- SEE the comments after "//" on each line below
- CONNECTIONS:
-
-
- V1.00 09/11/12
Questions: terry@yourduino.com */
/*-----( Import needed libraries )-----*/
/*-----( Declare Constants and Pin Numbers )-----*/
/*-----( Declare objects )-----*/
/*-----( Declare Variables )-----*/
#include <LiquidCrystal.h> // include the LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// INPUT: Potentiometer should be connected to 5V and GND
int potPin = 0; // Potentiometer output connected to analog pin 1
int potVal = 0; // Variable to store the input from the potentiometer
int potValue2 = 0; // final display variable MPH
int potValue3 = 0; // final display variable RPM
// OUTPUT: Use digital pins 9-11, the Pulse-width Modulation (PWM) pins
// LED's cathodes should be connected to digital GND
int redPin = 9; // Red LED, connected to digital pin 9
int grnPin = 10; // Green LED, connected to digital pin 10
int bluPin = 8; // Blue LED, connected to digital pin 8
// Program variables
int redVal = 0; // Variables to store the values to send to the pins
int grnVal = 0;
int bluVal = 0;
void setup() /****** SETUP: RUNS ONCE ******/
{
lcd.begin(16, 2); // lcd rows and columns
lcd.print(" Flywheel"); // title of sorts
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
potVal = analogRead(potPin); // read the potentiometer value at the input pin
if (potVal < 510) // Lowest third of the potentiometer's range (0-340)
{
potVal = (potVal * 3) / 4; // Normalize to 0-255
redVal = 0; // Red off
grnVal = 0; // Green off
bluVal = 255; // Blue full to off
}
else if (potVal < 920) // Middle third of potentiometer's range (341-681)
{
potVal = ( (potVal - 341) * 3) / 4; // Normalize to 0-255
redVal = 0; // Red off
grnVal = 255; // Green from full to off
bluVal = 0; // Blue off
}
else // Upper third of potentiometer"s range (682-1023)
{
potVal = ( (potVal - 983) * 3) / 4; // Normalize to 0-255
redVal = 255; // Red from off to full
grnVal = 0; // Green off
bluVal = 0; // Blue off
}
analogWrite(redPin, redVal); // Write values to LED pins
analogWrite(grnPin, grnVal);
analogWrite(bluPin, bluVal);
// read then divide the input(max 1020 in this case) by 10
potVal = analogRead(potPin) / 10 ;
// divide by 1.0 to get percentage
potValue2 = potVal / 1.02;
potValue3 = potVal * 8;
// set cursor to second row, first column
lcd.setCursor(1, 1);
//display RPM
//print RPM:
lcd.print("RPM:");
lcd.print(potValue3);
// set cursor to second row, first column
lcd.setCursor(9, 1);
//display final percentage
//print the MPH:
lcd.print("MPH:");
lcd.print(potValue2);
//wait 0.1 seconds
delay(100);
//wipe the extra characters
lcd.print(" ");
delay(1);
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
//*********( THE END )***********