#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int potPin1 = A0;
float val;
float RPM;
//int potPin2 = A2;
void setup() {
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
//lcd.setCursor(3,0);
//lcd.print("Hello, world!");
//lcd.setCursor(2,1);
//lcd.print("Ywrobot Arduino!");
//pinMode(potPin1, INPUT);
//pinMode(potPin2, INPUT);
// put your setup code here, to run once:
DDRA |= B00111111; //6 LEDs as output from PA0-PA5
PORTA &= B00000000; //test the LEDS are working
delay(2000);
PORTA &= B11111111; //set LOW all LEDS
}
void loop() {
val = analogRead(potPin1);
RPM = map(val,0,1023,750,3800);
//lcd.clear();
lcd.setCursor(0,0); // Sets the cursor to col 0 and row 0
lcd.print("target RPM:"); // Prints Sensor Val: to LCD
lcd.print(RPM); // Prints value on RPM to LCD
lcd.setCursor(0,1);
lcd.print("Slider Read:");
lcd.print(val);
//Common GND, LOW is TRUE or 1
// put your main code here, to run repeatedly:
if(RPM >= 1000){
//PORTA = B00000001; //Sets only PA0 to HIGH
PORTA &= ~(1<<PA0);
} else {PORTA |= (1<<PA0);}
if(RPM >= 1500){
PORTA &= ~B00000010;
} else {PORTA |= B00000010;}
if(RPM >= 2000){
PORTA &= ~(1<<PA2);
} else {PORTA |= (1<<PA2);}
if(RPM >= 2500){
PORTA &= ~(1<<PA3);
} else {PORTA |= (1<<PA3);}
if(RPM >= 3000){
PORTA &= ~(1<<PA4);
} else {PORTA |= (1<<PA4);}
if(RPM >= 3500){
PORTA &= ~(1<<PA5);
} else {PORTA |= (1<<PA5);}
//delay(100); //no delay in the loop for now
} //main loop
//Sets only PA0 to HIGH
//PORTA |= (1<<PA0);
//PORTA |= B00000001;
//set only PA1 to LOW
//PORTA &= ~(1<<PA1);
//PORTA &= B11111110;