// There is going to be a neo 6m gps module in the irl version for speed
// Oled display is being worked on
// there's also going to be a hall effect sensor for rpm
// variable z and potentiometer for simulating speed
// another potentiometer is gonna be added for simulating rpm
// the speed and rpm are gonna be displayed on the oled
#include <U8g2lib.h>
#include <FastLED.h>
#define max_l2 56
#define max_l1 48
#define max_r2 32
#define max_r1 24
#define d1 80
#define d2 80
#define d3 150
#define datapin 12
#define Led_tleft 11
#define Led_tright 4
#define Led_flight A2
#define Led_hazard 3
#define Switch1_tleft 7
#define Switch1_tright 6
#define Switch2_off 2
#define Switch3_hazard 10
#define Switch4_flight 9
#define Button_buzzer 8
#define buzzerpin 13
#define potentiometer_pin A1
#define numberpx_backleft 16
#define numberpx_backright 16
#define numberpx_speedometer 24
const int numberpx = numberpx_speedometer + numberpx_backright + numberpx_backleft;
CRGB leds[numberpx];
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ A5, /* data=*/ A4, /* reset=*/ U8X8_PIN_NONE);
int y; int x;
int potent_r; int mapped_p;
static int z;
void setup() {
Serial.begin(9600);
u8g2.begin();
FastLED.addLeds<WS2812B, datapin, GRB>(leds, numberpx);
pinMode(Switch1_tleft, INPUT_PULLUP);
pinMode(Switch1_tright, INPUT_PULLUP);
pinMode(Switch2_off, INPUT_PULLUP);
pinMode(Switch3_hazard, INPUT_PULLUP);
pinMode(Switch4_flight, INPUT_PULLUP);
pinMode(Button_buzzer, INPUT_PULLUP);
pinMode(potentiometer_pin, INPUT);
pinMode(Led_flight, OUTPUT);
pinMode(buzzerpin, OUTPUT);
pinMode(Led_tleft, OUTPUT);
pinMode(Led_tright, OUTPUT);
pinMode(Led_hazard, OUTPUT);
}
void loop() {
static int y = 0;
static int x = 0;
if (digitalRead(Switch3_hazard) == LOW) {
hazard();
digitalWrite(Led_hazard, HIGH);
} else if (digitalRead(Switch2_off) == LOW) {
FastLED.clear();
fill_solid(&leds[24], 33, CRGB(251, 119, 92));
FastLED.show();
digitalWrite(Led_tleft, LOW);
digitalWrite(Led_tright, LOW);
digitalWrite(Led_hazard, LOW);
} else if (digitalRead(Switch1_tright) == LOW) {
hahar();
digitalWrite(Led_tleft, LOW);
digitalWrite(Led_tright, HIGH);
digitalWrite(Led_hazard, LOW);
} else if (digitalRead(Switch1_tleft) == LOW) {
hahal();
digitalWrite(Led_tleft, HIGH);
digitalWrite(Led_tright, LOW);
digitalWrite(Led_hazard, LOW);}
if (digitalRead(Button_buzzer) == LOW) {
tone(buzzerpin, 1000);
} else {noTone(buzzerpin);}
if (digitalRead(Switch4_flight) == LOW) {
digitalWrite(Led_flight, HIGH);
} else {digitalWrite(Led_flight, LOW);}
int potent_r = analogRead(potentiometer_pin);
int mapped_p = map(potent_r, 0, 1023, 0, 72);
int z = map(potent_r, 0, 1023, 24, 0);
int za = 24 - z;
Serial.println(mapped_p);
Serial.println(z);
fill_solid(&leds[0], z, CRGB::Black);
fill_solid(&leds[z], za, CRGB(255, 85, 51));
FastLED.show();
delay(100);
}
void right() {
for (int x = max_r2; x >= max_r1; x--) {
leds[x] = CRGB(251, 119, 92);
FastLED.show();
delay(d1);
}
if (x == max_r1) {
x = max_r2;
} fill_solid(&leds[24], 16, CRGB::Black); FastLED.show();
}
void left() {
for (int y = max_l1; y < max_l2; y++) {
leds[y] = CRGB(251, 119, 92); // Orange color
FastLED.show();
delay(d2);
} fill_solid(&leds[40], 16, CRGB::Black); FastLED.show();
}
void hazard() {
fill_solid(&leds[24], 33, CRGB(75, 255, 135));
FastLED.show();
delay(d3);
fill_solid(&leds[24], 33, CRGB(98, 44, 33));
FastLED.show();
delay(d3);
}
void hahal() {
leds[40] = CRGB(75, 255, 135);
fill_solid(&leds[48], 8, CRGB(75, 255, 135));
FastLED.show();
delay(d2);
leds[40] = CRGB(98, 44, 33);
fill_solid(&leds[48], 8, CRGB(98, 44, 33));
FastLED.show();
delay(d1);
}
void hahar() {
fill_solid(&leds[24], 9, CRGB(75, 255, 135));
FastLED.show();
delay(d2);
fill_solid(&leds[24], 9, CRGB(98, 44, 33));
FastLED.show();
delay(d1);
}