I've tried everything from re writing the code to trying to somehow replace the whole "if" function and it didn't work. Can anyone take a look at it?
Thanks in advance
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
const int tipkalo = A0;
const int tipkalo2 = A1;
const int switcc1 = A2;
const int switcc2 = A3;
const int switcc3 = A4;
const int switcc4 = A5;
const int IR_sensor = A6;
const int IR_led_transistor = 2;
const int C_LED = 3;
const int P_LED = 4;
const int kv = 5;
const int mosfet = 6;
int w_rpm = 0;
float hall_thresh = 7.0;
void setup(){
lcd.begin(16, 2);
lcd.print("2step system by");
lcd.setCursor(0, 1);
lcd.print("AnteLo");
pinMode(tipkalo, INPUT);
pinMode(C_LED, OUTPUT);
pinMode(P_LED, OUTPUT);
pinMode(IR_led_transistor, OUTPUT);
pinMode(mosfet, OUTPUT);
pinMode(kv, INPUT);
pinMode(IR_sensor, INPUT);
digitalWrite(C_LED, LOW);
digitalWrite(P_LED, LOW);
digitalWrite(mosfet, HIGH);
delay(1500);
digitalWrite(IR_led_transistor, HIGH);
}
void loop()
{
float hall_count = 1;
float start = micros();
bool on_state = false;
while(true){
if (digitalRead(IR_sensor)==0){
if (on_state==false){
on_state = true;
hall_count+=1.0;
}
} else{
on_state = false;
}
if (hall_count>=hall_thresh){
break;
}
}
float end_time = micros();
float time_passed = ((end_time-start)/1000000.0);
float rpm_val = (hall_count/time_passed)*6;
delay(1);
if (digitalRead(switcc1) == HIGH && rpm_val >= 1600){
w_rpm = w_rpm + 1500;
}
if (digitalRead(switcc2) == HIGH && rpm_val >= 1600){
w_rpm = w_rpm + 500;
}
if (digitalRead(switcc3) == HIGH && rpm_val >= 1600){
w_rpm = w_rpm + 500;
}
if (digitalRead(switcc4) == HIGH && rpm_val >= 1600){
w_rpm = w_rpm + 250;
}
if (digitalRead(tipkalo) == HIGH && w_rpm == 0){
lcd.setCursor(0, 1);
lcd.print("no jumpers set");
}
if (digitalRead(tipkalo) == HIGH && rpm_val >= w_rpm){
lcd.begin(16, 2);
lcd.print("2step active");
lcd.setCursor(0,1);
lcd.print(w_rpm);
lcd.print("rpm");
digitalWrite(mosfet, LOW);
}
if (digitalRead(tipkalo2) == HIGH && w_rpm >= 1400) {
lcd.begin(16, 2);
lcd.print("2step active");
lcd.setCursor(0,1);
lcd.print(w_rpm);
lcd.print("rpm");
digitalWrite(mosfet, LOW);
}
if (digitalRead(kv) == HIGH && w_rpm >= 4200){
lcd.setCursor(3, 1);
lcd.print("FLAT SHIFT");
digitalWrite(mosfet, LOW);
}
else {
delay(100);
lcd.begin(16, 2);
lcd.print("2step deactive");
digitalWrite(mosfet, HIGH);
}
}
_2step_v1.1_final.ino (2.5 KB)