Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Car alarm project G3orG3 @2016
- /*
- TO ADD:
- -MORE PINS
- -RGB LED
- -music visualizer
- -zener diodes
- -voltage down using 2 resistors
- -
- EXPANDER CONNECTIONS:
- 11 cs/ss
- 12 sck
- 13 mosi
- 14 miso
- // Connect pins #15, 16 and 17 of the expander to ground (address selection)
- // Connect pin #9 of the expander to 5V (power)
- // Connect pin #10 of the expander to ground (common ground)
- // Connect pin #18 through a ~10kohm resistor to 5V (reset pin, active low)
- OUTSIDE - need to be connected outsite the box
- INSIDE - inside with the arduino
- NEED UPDATE
- PINOUT:
- 0-(TX) bluetooth
- 1-(RX) bluetooth
- 2-Expander 11 (cip select) ss/cs
- 3-(PWM)CAR-MOSFET-PWM-USAlights (OUTPUT)
- 4-BOARD-BUZZER
- 5-(PWM)CAR-MOSFET-PWM-LEDstrip-RED (OUTPUT)
- 6-(PWM)
- 7-RST (INPUT)
- 8-SDA (INPUT) cip select
- 9-(PWM)CAR-MOSFET-PWM-LEDstrip-BLUE (OUTPUT)
- 10-(PWM)CAR-MOSFET-PWM-LEDstrip-GREEN (OUTPUT)
- 11-(PWM)RFID-MOSI + Expander 13(INPUT)
- 12-MISO + Expander 14 (INPUT)j
- 13-SCK + Expander 12 (INPUT)
- 0-
- 1-
- 2-POTENTIOMETER for menu, dimming (INPUT)
- 3-CAR-VOLTAGE-determiner (scaled down) (INPUT)
- 4-LCD+EXPANDER-SDA (INPUT)
- 5-LCD+EXPANDER-SCL (INPUT)
- 6-SENSOR-temperature (INPUT)
- 7-
- EXPANDER A
- 8-BUTTON-More/custom/ok
- 7-SWITCH-led Strip (INPUT)
- 6-SWITCH-USA lights (INPUT)
- 5-SWITCH-alarm (INPUT)
- 4-SENSOR-piezo (INPUT)
- 3-SENSOR-PIR (INPUT)
- 2-
- 1-
- EXPANDER B
- 9-CAR-NPN-lock (OUTPUT)
- 10-CAR-NPN-unlock (OUTPUT)
- 11-CAR-NPN-alarmhorn (OUTPUT)
- 12-CAR-NPN-truck-open (OUTPUT)
- 13-CAR-RELAY(12V line - car is locked ) (INPUT)
- 14-CAR-IGNITION(12V line - engine is started) (INPUT)
- 15-CAR-RELAY-RADIO (OUTPUT)
- 16-
- */
- // INCLUDING / DEFINE LIBRARYs
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
- #include <LCD.h>
- #include <LcdBarGraphX.h>
- #include <EEPROM.h>
- #include <SPI.h> // We use this library, so it must be called here.
- #include <MCP23S17.h> // Here is the new class to make using the MCP23S17 easy.
- MCP mcp(0, 2);
- //#include <SoftwareSerial.h>
- //SoftwareSerial BTSerial(8, A1); // RX | TX
- //led strip
- const int ledPin = 6; //led strip toggler //EXPANDER
- const int ledRPin = 5; //led RED
- const int ledGPin = 10; //led GREEN
- const int ledBPin = 9; //led BLUE
- //USA lights
- const int usaPin = 7; // USA LIGHTS toggler //EXPANDER
- const int usaoutPin = 3; // USA LIGHTS
- //truck unlocker
- const int truckopenPin = 12; // truck unlocker MOTOR //EXPANDER
- // sensor pin
- //alarm + locker
- const int sensorVPin = 3; // piezo vibration sensor module //EXPANDER
- const int alarmPin = 5; // ALARM toggler //EXPANDER
- const int lockPin = 9; // pin to the transistor who lock the door //EXPANDER
- const int unlockPin = 10; // pin to the transistor who unlock the door //EXPANDER
- const int carlockPin = 13; // car locked ? //EXPANDER
- const int contactPin = 14; // car contact on ? //EXPANDER
- const int triggerPin = 11; // horn, lights, car wipers ... //EXPANDER
- //more
- const int potPin = A2; // potentiometer
- const int buzzerPin = 4; // buzzer
- const int tempPin = A6; // temperature
- const int voltagePin = A7; // car volage
- const int buttonPin = 8; // button //EXPANDER
- const int blkey = 16; //EXPANDER
- const int blon = 2; //EXPANDER
- // Settings
- int redVal = 0; // Variables to store the values to send to the pins
- int grnVal = 0;
- int bluVal = 0;
- int truckVal = 0;
- // int RFIDVal = 1;
- int alarmtime = 15; // time for alarm to turn off IN SECOUNDS
- int timeToKnock = 3; // amout of time to hear knocks in SECOUNDS !
- int knocks = 3; // how many knocks
- int usalight = 50; // % of the lights
- int ledlight = 55; //% of the interior light
- //progress bars
- LcdBarGraphX lbg(&lcd, 7, 9, 1);
- LcdBarGraphX lbg1(&lcd, 7, 0, 1);
- LcdBarGraphX lbg2(&lcd, 16, 0, 1);
- LcdBarGraphX lbg3(&lcd, 16, 0, 0);
- //progressbar animation
- void filldown() {
- for (int i = 0; i < 81; i++)
- {
- lbg2.drawValue( i, 80);
- delay(3);
- }
- }
- //progressbar animation
- void fillup() {
- for (int i = 0; i < 81; i++)
- {
- lbg3.drawValue( i, 80);
- delay(3);
- }
- }
- //custom car animation
- byte off[8] = {
- 0b00000,
- 0b10001,
- 0b10001,
- 0b01010,
- 0b00100,
- 0b01010,
- 0b10001,
- 0b10001
- };
- byte on[8] = {
- 0b00000,
- 0b00001,
- 0b00010,
- 0b10100,
- 0b11000,
- 0b10000,
- 0b00000,
- 0b00000
- };
- #define NOTE_B0 31
- #define NOTE_C1 33
- #define NOTE_CS1 35
- #define NOTE_D1 37
- #define NOTE_DS1 39
- #define NOTE_E1 41
- #define NOTE_F1 44
- #define NOTE_FS1 46
- #define NOTE_G1 49
- #define NOTE_GS1 52
- #define NOTE_A1 55
- #define NOTE_AS1 58
- #define NOTE_B1 62
- #define NOTE_C2 65
- #define NOTE_CS2 69
- #define NOTE_D2 73
- #define NOTE_DS2 78
- #define NOTE_E2 82
- #define NOTE_F2 87
- #define NOTE_FS2 93
- #define NOTE_G2 98
- #define NOTE_GS2 104
- #define NOTE_A2 110
- #define NOTE_AS2 117
- #define NOTE_B2 123
- #define NOTE_C3 131
- #define NOTE_CS3 139
- #define NOTE_D3 147
- #define NOTE_DS3 156
- #define NOTE_E3 165
- #define NOTE_F3 175
- #define NOTE_FS3 185
- #define NOTE_G3 196
- #define NOTE_GS3 208
- #define NOTE_A3 220
- #define NOTE_AS3 233
- #define NOTE_B3 247
- #define NOTE_C4 262
- #define NOTE_CS4 277
- #define NOTE_D4 294
- #define NOTE_DS4 311
- #define NOTE_E4 330
- #define NOTE_F4 349
- #define NOTE_FS4 370
- #define NOTE_G4 392
- #define NOTE_GS4 415
- #define NOTE_A4 440
- #define NOTE_AS4 466
- #define NOTE_B4 494
- #define NOTE_C5 523
- #define NOTE_CS5 554
- #define NOTE_D5 587
- #define NOTE_DS5 622
- #define NOTE_E5 659
- #define NOTE_F5 698
- #define NOTE_FS5 740
- #define NOTE_G5 784
- #define NOTE_GS5 831
- #define NOTE_A5 880
- #define NOTE_AS5 932
- #define NOTE_B5 988
- #define NOTE_C6 1047
- #define NOTE_CS6 1109
- #define NOTE_D6 1175
- #define NOTE_DS6 1245
- #define NOTE_E6 1319
- #define NOTE_F6 1397
- #define NOTE_FS6 1480
- #define NOTE_G6 1568
- #define NOTE_GS6 1661
- #define NOTE_A6 1760
- #define NOTE_AS6 1865
- #define NOTE_B6 1976
- #define NOTE_C7 2093
- #define NOTE_CS7 2217
- #define NOTE_D7 2349
- #define NOTE_DS7 2489
- #define NOTE_E7 2637
- #define NOTE_F7 2794
- #define NOTE_FS7 2960
- #define NOTE_G7 3136
- #define NOTE_GS7 3322
- #define NOTE_A7 3520
- #define NOTE_AS7 3729
- #define NOTE_B7 3951
- #define NOTE_C8 4186
- #define NOTE_CS8 4435
- #define NOTE_D8 4699
- #define NOTE_DS8 4978
- // 2226,f8,949be1 -Geo phone
- // AT+RNAME?<PR> OK
- // AT+FSAD=<PR> OK
- void setup() {
- lcd.setCursor(1, 0); //Start at character 4 on line 0
- lcd.print("Status:");
- //``````````````` LCD EXPANDER
- lcd.begin(16, 2); // initialize the lcd for 16 chars 2 lines, turn on backlight
- SPI.begin(); // start the SPI library
- mcp.begin(); // expander bank A / 0
- lcd.createChar(7, on); //create custom car
- lcd.createChar(8, off); //create custom car
- lcd.setCursor(0, 1); //Start at character 4 on line 0
- lcd.print("Starting LCD,MCP");
- delay(1000);
- tone(buzzerPin, NOTE_B5, 100);
- //```````````````BLUETOOTH
- lcd.setCursor(0, 1); //Start at character 4 on line 0
- lcd.print("Check Bluetooth");
- delay(500);
- tone(buzzerPin, NOTE_B5, 100);
- mcp.pinMode(blon, OUTPUT);
- mcp.digitalWrite(blon, HIGH); //power on the bluetooth
- mcp.pinMode(blkey, OUTPUT);
- mcp.digitalWrite(blkey, HIGH); //power on AT COMMAND on bluetooth
- delay(100);
- // BTSerial.begin(38400); // HC-05 default speed in AT command more
- delay(100);
- // BTSerial.write("AT+NAME"); //example command
- //if (BTSerial.available()) {
- // lcd.print(BTSerial.read());
- // }
- // BTSerial.findBaud(); // search for bluetooth band
- /*
- // Play 1-up sound
- tone(buzzerPin, NOTE_E6, 125);
- delay(130);
- tone(buzzerPin, NOTE_G6, 125);
- delay(130);
- tone(buzzerPin, NOTE_E7, 125);
- delay(130);
- tone(buzzerPin, NOTE_C7, 125);
- delay(130);
- tone(buzzerPin, NOTE_D7, 125);
- delay(130);
- tone(buzzerPin, NOTE_G7, 125);
- */
- // for (int i = 0; i < 20; i++) //Start-up animation
- // {
- // lcd.backlight();
- // delay(i * 4);
- // lcd.noBacklight();
- // delay(i * 4);
- // }
- // lcd.backlight(); // finish with backlight on
- //```````````````PINS
- lcd.setCursor(0, 1); //Start at character 4 on line 0
- lcd.print("Register pins");
- delay(500);
- tone(buzzerPin, NOTE_B5, 100);
- //set the pins from arduino
- pinMode(buzzerPin, OUTPUT);
- pinMode(ledRPin, OUTPUT);
- pinMode(ledGPin, OUTPUT);
- pinMode(ledBPin, OUTPUT);
- pinMode(potPin, INPUT);
- // pinMode(micPin, INPUT);
- // pinMode(sMicPin, INPUT);
- pinMode(voltagePin, INPUT);
- pinMode(tempPin, INPUT);
- pinMode(usaoutPin, OUTPUT);
- //set the pins from expander 0
- mcp.pinMode(lockPin, OUTPUT);
- mcp.pinMode(unlockPin, OUTPUT);
- mcp.pinMode(triggerPin, OUTPUT);
- mcp.pinMode(truckopenPin, OUTPUT);
- mcp.pinMode(carlockPin, INPUT);
- mcp.pinMode(contactPin, INPUT);
- // mcp.pinMode() radio relay
- //set the pins from expander 1
- mcp.pinMode(buttonPin, INPUT);
- mcp.pullupMode(buttonPin, HIGH);
- mcp.pinMode(alarmPin, INPUT);
- mcp.pullupMode(alarmPin, HIGH);
- mcp.pinMode(usaPin, INPUT);
- mcp.pullupMode(usaPin, HIGH);
- mcp.pinMode(ledPin, INPUT);
- mcp.pullupMode(ledPin, HIGH);
- mcp.pinMode(sensorVPin, INPUT);
- // mcp.pinMode(sensorPPin, INPUT);
- lcd.setCursor(0, 1); //Start at character 4 on line 0
- lcd.print("Restore settings");
- delay(500);
- tone(buzzerPin, NOTE_B5, 100);
- /*
- // check();
- tone(buzzerPin, NOTE_G7, 125);
- delay(100);
- // RESTORE SETTINGS
- redVal = EEPROM.read(0);
- grnVal = EEPROM.read(1);
- bluVal = EEPROM.read(2);
- truckVal = EEPROM.read(3);
- //RFIDVal = EEPROM.read(4);
- alarmtime = EEPROM.read(5);
- timeToKnock = EEPROM.read(6);
- knocks = EEPROM.read(7);
- usalight = EEPROM.read(8);
- ledlight = EEPROM.read(9);
- delay(200);
- // analogWrite(ledRPin, redVal); // Write values to LED pins
- // analogWrite(ledGPin, grnVal);
- // analogWrite(ledBPin, bluVal);
- tone(buzzerPin, NOTE_G7, 125);
- lcd.clear();
- delay(100);
- */
- lcd.setCursor(0, 1); //Start at character 4 on line 0
- lcd.print("All Done!");
- delay(500);
- tone(buzzerPin, NOTE_B5, 100);
- }
- void unlock_door()
- {
- mcp.digitalWrite(unlockPin, HIGH);
- delay(200);
- mcp.digitalWrite(unlockPin, LOW);
- delay(1000);
- }
- void lock_door()
- {
- mcp.digitalWrite(lockPin, HIGH);
- delay(200);
- mcp.digitalWrite(lockPin, LOW);
- delay(1000);
- }
- int usaStatus = 0; //usa toggler status
- int ledStatus = 0; //led toggler status
- int alarmStatus = 0; //alarm toggler status
- //int rfidStatus = 0; //
- int menudisplaymode = 0; // used for percente / progressbar
- int clicktime = (2500 / 5 / 100); //time to enter menu/select
- int menupage = 0; // menu page
- int menusel = 0; // menu selected item
- int menumode = 0;
- int menudone = 0; //the value of the setting that must be applied
- int before = 0; //used to enter settings old pot
- int beforepot = 0; //used to navigate in homepage old pot
- int cur = 0;
- int count = 0;
- int idlecount = 0;
- int potVal = 0;
- int settingspos = 0; //cursor pos for settings
- int lcdf = 0; //used for lcd clearing function
- int lcdclear = 0; //used for clear lcd timer
- int active = 1; //used to know if the homepage is active or not
- int alarmtrig = 0; //alarm triggered
- int blcon = 0; // is the bluetooth connected to a device ?
- int blinterval = 0; // bluetooth function interval
- int blstate = 0; // 0 scan 1 receive
- /* --------------EEPROM
- EEPROM.write(addr, val);
- EEPROM.read(address);
- ADDRs -
- -HOMEPAGE
- 0-red
- 1-green
- 2-blue
- 3-truckVal 1/0
- 4-RFIDVal 1/0
- 5-alarmtime
- 6-timeToKnock
- 7-knocks
- 8-usalight
- 9-ledlight
- */
- void click_sound() {
- tone(buzzerPin, NOTE_B5, 100);
- }
- void toggle_sound() {
- tone(buzzerPin, 5000, 50);
- }
- void error_sound() {
- tone(buzzerPin, 1000, 200);
- }
- void loop()
- {
- delay(100);
- //BEGIN HOMEPAGES !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- if (lcdf == 0) {
- if (menumode <= 0) {
- if (active == 1) {
- if (menumode == 0) { //Homepage 0 -- temperature + lock/unlock
- lcd.backlight();
- lcd.setCursor(0, 1);
- if (mcp.digitalRead(carlockPin) == LOW) {
- lcd.print("<Incuie masina>");
- if (mcp.digitalRead(buttonPin) == LOW) {
- lcd.setCursor(0, 1);
- toggle_sound();
- lcd.print("Incuiata!! ");
- lock_door();
- delay(500);
- }
- }
- else {
- lcd.print("<Descuie masina>");
- if (mcp.digitalRead(buttonPin) == LOW) {
- unlock_door();
- toggle_sound();
- lcd.setCursor(0, 1);
- lcd.print("Descuiata!! ");
- delay(500);
- }
- }
- lcd.setCursor(0, 0);
- if (blcon = 0) {
- lcd.print("BL");
- lcd.write(8);
- }
- else {
- lcd.print("BL");
- lcd.write(7);
- }
- lcd.print(" ");
- if (mcp.digitalRead(contactPin) == LOW) {
- lcd.print("CAR");
- lcd.write(7);
- }
- else {
- lcd.print("CAR");
- lcd.write(8);
- }
- lcd.print(" ");
- float sensor = analogRead(tempPin);
- float volt = (5.0 * sensor) / 1024.0;
- float milivolt = volt * 100;
- int c = milivolt - 273.15;
- // c = c - 16; //calibration
- lcd.print(c);
- lcd.print(char(223));
- lcd.print("C>");
- } //end menumode 0 ( homepage 1 )
- //Homepage 1 -- LED color
- if (menumode == -1) {
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("<Culoarea Banda>");
- lcd.setCursor(0, 1);
- lcd.print("R:");
- lcd.print(redVal);
- lcd.print(" G:");
- lcd.print(grnVal);
- lcd.print(" B:");
- lcd.print(bluVal);
- if (mcp.digitalRead(buttonPin) == LOW) {
- menumode = -11;
- click_sound(); // --- buzzer sound
- delay(400);
- }
- }
- if (menumode == -11) {
- lcd.setCursor(0, 1);
- lcd.print("R:");
- lcd.print(redVal);
- lcd.print(" G:");
- lcd.print(grnVal);
- lcd.print(" B:");
- lcd.print(bluVal);
- // -----------------------------------------BEGIN COLOR MIXER
- //--------------------------------------------------------
- potVal = analogRead(potPin); // read the potentiometer value at the input pin
- if (potVal < 341) // Lowest third of the potentiometer's range (0-340)
- {
- potVal = (potVal * 3) / 4; // Normalize to 0-255
- redVal = 256 - potVal; // Red from full to off
- grnVal = potVal; // Green from off to full
- bluVal = 1; // Blue off
- }
- else if (potVal < 682) // Middle third of potentiometer's range (341-681)
- {
- potVal = ( (potVal - 341) * 3) / 4; // Normalize to 0-255
- redVal = 1; // Red off
- grnVal = 256 - potVal; // Green from full to off
- bluVal = potVal; // Blue from off to full
- }
- else // Upper third of potentiometer"s range (682-1023)
- {
- potVal = ( (potVal - 683) * 3) / 4; // Normalize to 0-255
- redVal = potVal; // Red from off to full
- grnVal = 1; // Green off
- bluVal = 256 - potVal; // Blue from full to off
- }
- analogWrite(ledRPin, (redVal - ((redVal * ledlight) / 100))); // Write values to LED pins
- analogWrite(ledGPin, (grnVal - ((grnVal * ledlight) / 100)));
- analogWrite(ledBPin, (bluVal - ((bluVal * ledlight) / 100)));
- delay(5);
- //--------------------------------------------------------
- //------------------------------------------ END COLOR MIXER
- if (mcp.digitalRead(buttonPin) == LOW) {
- EEPROM.write(0, redVal); //write to memory
- EEPROM.write(1, grnVal);
- EEPROM.write(2, bluVal);
- idlecount = 0;
- menumode = 0;
- delay(300);
- click_sound(); // --- buzzer sound
- }
- } //end homepage 1
- //Homepage 2 -- Notificari
- if (menumode == -2) {
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("V baterie:");
- float vbat = analogRead(voltagePin);
- float temp2 = (vbat * (5.0 / 1023.0));
- lcd.print( temp2 / 0.3024 );
- lcd.setCursor(0, 1);
- lcd.print(" V:");
- lcd.print(mcp.digitalRead(sensorVPin));
- lcd.print(" Lk:");
- lcd.print(mcp.digitalRead(carlockPin));
- lcd.print(" C:");
- lcd.print(mcp.digitalRead(contactPin));
- if (mcp.digitalRead(buttonPin) == LOW) {
- click_sound(); // --- buzzer sound
- delay(400);
- //reseteaza notificari
- }
- } // end homepage 2
- //Homepage 3 -- Open truck
- if (menumode == -3) {
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("<Porbagaj>");
- lcd.setCursor(0, 1);
- lcd.print("<deschide>");
- if (mcp.digitalRead(buttonPin) == LOW) {
- //OPEN TRUCK
- click_sound(); // --- buzzer sound
- menumode = 0;
- idlecount = 0;
- }
- } // end homepage 3
- //Homepage 4 -- Open settings
- if (menumode == -4) {
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("<Setari>");
- lcd.setCursor(0, 1);
- lcd.print("<deschide>");
- if (mcp.digitalRead(buttonPin) == LOW) {
- //OPEN settings
- click_sound(); // --- buzzer sound
- menumode = 1;
- idlecount = 0;
- delay(400);
- }
- } // end homepage 4
- idlecount = idlecount + 1;
- } //end if (active = 1)
- //keep the page with the pot value
- if (menumode > -5) {
- if (menumode <= 0) {
- int pot = map(analogRead(potPin), 0, 1000, 0, -4); // number of settings submenus // to EDIT ~!~~~~~~~~~~~~~
- menusel = pot; //read the selection from the pot
- if (menumode != menusel) { //only if is not already set
- click_sound();
- menumode = menusel;
- lcd.clear();
- active = 1;
- idlecount = 0;
- delay(50);
- }
- }
- }
- if (idlecount >= 400) {
- if (active == 1) {
- active = 0;
- lcd.clear();
- lcd.setCursor(0, 0);
- menumode = 0;
- lcd.print("Stand-by mode");
- lcd.noBacklight();
- toggle_sound();
- idlecount = 0;
- }
- }
- } //END HOMEPAGES
- } // end lcd clear
- //LCD CLEAR FUNCTION
- // use lcdclear = x ms (def:1700)
- // 1 sec = 10 steps
- // 1,7 sec = 17 steps
- if (lcdf == 1) {
- if (lcdclear < 17) {
- lcdclear = lcdclear + 1;
- }
- if (lcdclear >= 17) {
- lcdclear = 0;
- lcdf = 0;
- lcd.clear();
- delay(150); //default time for animations
- }
- }
- // END LCD CLEAR FUNCTION
- if (menumode <= 0) {
- // BEGIN usalights TOGGLER
- if (mcp.digitalRead(usaPin) == HIGH) { //if toggler is ON
- if (usaStatus == 0) {
- analogWrite(usaoutPin, map(usalight, 0, 100, 0, 255)); //set PWM of usa lights
- lcd.clear();
- lcd.backlight();
- toggle_sound();
- usaStatus = 1;
- lcd.setCursor(0, 0);
- lcd.print("USA Lights ON");
- lcd.setCursor(0, 1);
- lcd.print(usalight);
- lcd.print("%");
- lcdclear = 0;
- lcdf = 1;
- }
- }
- else //if toggler is off
- {
- if (usaStatus == 1) {
- analogWrite(usaoutPin, 0); //set PWM of usa lights
- lcd.clear();
- lcd.backlight();
- toggle_sound();
- usaStatus = 0;
- lcd.setCursor(0, 0);
- lcd.print("USA Lights OFF");
- lcdclear = 0;
- lcdf = 1;
- }
- }
- // END usalights TOGGLER
- // BEGIN LED STRIP toggler
- if (mcp.digitalRead(ledPin) == HIGH) { //if toggler is ON
- if (ledStatus == 0) {
- delay(50);
- lcd.clear();
- lcd.backlight();
- toggle_sound();
- ledStatus = 1;
- lcd.setCursor(0, 0);
- lcd.print("Banda LED: ");
- lcd.setCursor(0, 1);
- lcd.print(ledlight);
- lcd.print("%");
- lcdclear = 0;
- lcdf = 1;
- analogWrite(ledRPin, (redVal - ((redVal * ledlight) / 100))); // Write values to LED pins
- analogWrite(ledGPin, (grnVal - ((grnVal * ledlight) / 100)));
- analogWrite(ledBPin, (bluVal - ((bluVal * ledlight) / 100)));
- delay(10);
- }
- }
- else //if toggler is off
- {
- if (ledStatus == 1) {
- delay(50);
- lcd.clear();
- lcd.backlight();
- toggle_sound();
- ledStatus = 0;
- lcd.setCursor(0, 0);
- lcd.print("Banda LED OFF");
- lcdclear = 0;
- lcdf = 1;
- analogWrite(ledRPin, 0); // Write values to LED pins
- analogWrite(ledGPin, 0);
- analogWrite(ledBPin, 0);
- delay(10);
- }
- }
- // END LED STRIP toggler
- // 2226,f8,949be1 -Geo phone
- // AT+RNAME?<PR> OK
- // AT+FSAD=<PR> OK
- /*
- // BEGIN BLUETOOTH function
- blinterval = blinterval + 1;
- if (mcp.digitalRead(contactPin) == LOW) { //if the car is off
- if (mcp.digitalRead(carlockPin) == HIGH) { //if the car is locked
- if (blcon == 0) { //if bluetooth is disconnected
- if (blinterval == 10) { // and 1000 ms passes
- if (blstate == 0) {
- BTSerial.write("AT+RNAME?2226,f8,949be1"); //example command
- blstate = 1;
- }
- else {
- if (BTSerial.available()) {
- String temp = BTSerial.readString();
- if (temp == "OK") {
- blcon = 1;
- lcd.setCursor(0, 0);
- lcd.print("Merge");
- // unlock car
- }
- else { //if the answer is anything else
- lcd.setCursor(0, 0);
- lcd.print(temp);
- }
- }
- else {
- lcd.setCursor(0, 0);
- lcd.print("nu raspuns");
- }
- blstate = 0;
- }
- }
- }
- else { //if the bluetooth is connected
- }
- }
- }
- // END BLUETOOTH function
- */
- // BEGIN RFID function
- /*
- if (RFIDVal == 1) { //RFID SETTINGS
- if (mcp.digitalRead(contactPin) == LOW) { //if the car is NOT ignited
- int detectedsts = 0; // check_RFID();
- if (detectedsts = 1) { //if you detect my RFID
- if (mcp.digitalRead(carlockPin) == HIGH) { //if the car is locked
- if (rfidStatus == 0) {
- unlock_door();
- rfidStatus = 1;
- lcd.setCursor(0, 0);
- lcd.print("Deschid masina!");
- lcdclear = 0;
- lcdf = 1;
- }
- }
- else
- { // if the car is unlocked
- if (rfidStatus == 1) {
- lock_door();
- rfidStatus = 0;
- lcd.setCursor(0, 0);
- lcd.print("Inchid masina!");
- lcdclear = 0;
- lcdf = 1;
- }
- }
- }
- }
- }
- */
- // END RFID function toggler
- // BEGIN ALARM TOGGLER watchdog
- if (mcp.digitalRead(alarmPin) == HIGH) { //if the alarm is enabled
- if (alarmStatus == 0) {
- lcd.clear();
- lcd.backlight();
- toggle_sound();
- alarmStatus = 1;
- lcd.setCursor(0, 0);
- lcd.print("Alarm is ON");
- lcdf = 1;
- lcdclear = 0;
- }
- }
- else { //if the button is LOW
- if (alarmStatus == 1) {
- lcd.clear();
- lcd.backlight();
- toggle_sound();
- alarmStatus = 0;
- lcd.setCursor(0, 0);
- lcd.print("Alarm is OFF !");
- lcdf = 1;
- lcdclear = 0;
- }
- }
- // END AlARM TOGGLER feedback
- // BEGIN ALARM TRIGGER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- if (alarmStatus == 1) { //if the alarm is enabled
- if (alarmtrig == 0) {
- if (mcp.digitalRead(carlockPin) == HIGH) { //if the car is locked
- if (mcp.digitalRead(contactPin) == HIGH) { //if the car is locked
- if (mcp.digitalRead(sensorVPin) == LOW) { //if vibrations are detected
- alarmtrig = 1;
- mcp.digitalWrite(triggerPin, HIGH); //horn on
- error_sound(); //interior sound
- // lock_door(); //make sure the doors are locked
- // delay(alarmtime); //alarm time
- delay(3000); //alarm time
- alarmtrig = 0;
- mcp.digitalWrite(triggerPin, LOW); //horn off
- }
- }
- }
- }
- }
- // END ALARM TRIGGER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //BEGIN truck-opener
- // if truckVal == 1 {
- //need microphone OR knock sensor
- // }
- //END truck-opener
- }
- //SETTINGS MODE ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SETTINGS
- if (menumode >= 1) {
- if (menumode == 1) { //welcome message
- lcd.clear();
- lcd.setCursor(5, 0);
- lcd.write("SETARI");
- delay(1000);
- lcd.setCursor(4, 1);
- lcd.write("avansate");
- delay(1500);
- menumode = 2;
- menupage = 0;
- lcd.clear();
- click_sound(); // --- buzzer sound
- count = 0;
- }
- else { //menu
- //begin setting the selection
- int pot = map(analogRead(potPin), 0, 1025, 1, 7); // 7 = number of settings submenus
- menusel = pot; //read the selection from the pot
- lcd.setCursor(0, 0);
- lcd.print(" ");
- if (menupage <= 2) { //set it only if your out of a submenu
- lcd.setCursor(0, 1);
- lcd.print(" ");
- if ( (pot % 2) == 0) {
- lcd.setCursor(0, 1);
- lcd.print("~");
- if (settingspos == 0) {
- settingspos = 1;
- click_sound(); // --- buzzer sound
- }
- }
- else {
- lcd.setCursor(0, 0);
- lcd.print("~");
- if (settingspos == 1) {
- settingspos = 0;
- click_sound(); // --- buzzer sound
- }
- }
- //end of setting the selection
- //page switcher
- if (menusel >= 1 and menusel <= 2) {
- menupage = 0;
- }
- if (menusel >= 3 and menusel <= 4) {
- menupage = 1;
- }
- if (menusel >= 5 and menusel <= 6) {
- menupage = 2;
- }
- }
- if (menupage == 0) {
- lcd.setCursor(1, 0);
- lcd.print("1.LED interior ");
- lcd.setCursor(1, 1);
- lcd.print("2.US Lights ");
- }
- if (menupage == 1) {
- lcd.setCursor(1, 0);
- lcd.print("3.Alarma Hoti ");
- lcd.setCursor(1, 1);
- lcd.print("4.Porbagaj ");
- }
- if (menupage == 2) {
- lcd.setCursor(1, 0);
- lcd.print("5.Diagnostic ");
- lcd.setCursor(1, 1);
- lcd.print("6.Iesi ");
- }
- //LED STRIP MENU
- if (menupage >= 3) {
- if (menupage == 3) {
- lcd.setCursor(0, 0);
- lcd.print("Inainte: Dupa:");
- lbg1.drawValue( ledlight, 100);
- lbg.drawValue( analogRead(potPin), 1024);
- menudone = 1;
- }
- //USA LIGHTS MENU
- if (menupage == 4) {
- lcd.setCursor(0, 0);
- lcd.print("Inainte: Dupa:");
- lbg1.drawValue( usalight, 100);
- lbg.drawValue( analogRead(potPin), 1024);
- menudone = 2;
- }
- //ALARM MENU
- if (menupage == 5) {
- lcd.setCursor(0, 0);
- lcd.print("Inainte: Dupa:");
- lcd.setCursor(0, 1); //mid line
- lcd.print(alarmtime);
- lcd.print("/30s");
- lcd.setCursor(9, 1); //mid line
- lcd.print(map(analogRead(potPin), 0, 1025, 1, 30));
- lcd.print("/30s ");
- menudone = 3;
- }
- //TRUCK OPENER MENU
- if (menupage == 6) {
- lcd.setCursor(0, 0);
- lcd.print("Inainte: Dupa:");
- lcd.setCursor(0, 1); //mid line
- lcd.print(timeToKnock);
- lcd.print("/30s");
- lcd.setCursor(9, 1); //mid line
- //sssssssssssssssssssss
- lcd.print("/30s ");
- menudone = 4;
- }
- //Diagnostics menu
- if (menupage == 6) {
- lcd.setCursor(0, 0);
- lcd.print("pot:");
- lcd.print(analogRead(potPin)); // 16 - 8 = 8 ch's left
- lcd.print(" but:");
- lcd.print(mcp.digitalRead(ledPin));
- lcd.setCursor(0, 1); //mid line
- lcd.print(timeToKnock);
- lcd.print("/30s");
- lcd.setCursor(9, 1); //mid line
- lcd.print(map(analogRead(potPin), 0, 1025, 1, 30));
- lcd.print("/30s ");
- menudone = 5;
- }
- //exit
- if (menupage == 7) {
- menumode = 0;
- }
- lcd.setCursor(7, 1); //mid line
- lcd.print("[]");
- delay(100); //visualization fixer
- }
- if (mcp.digitalRead(buttonPin) == LOW) {
- click_sound(); // --- buzzer sound
- //LCD STRIP MENU
- if (menupage >= 3) { //back to menu from led strip settings
- delay(150);
- lcd.clear();
- lcd.setCursor(0, 0);
- if (menudone == 1) {
- ledlight = map(analogRead(potPin), 0, 1025, 0, 100); //set the new value
- lcd.print("Led opacity:");
- lcd.print(ledlight);
- lcd.print("%");
- EEPROM.write(9, ledlight);
- }
- if (menudone == 2) {
- usalight = map(analogRead(potPin), 0, 1025, 0, 100); //set the new value
- lcd.print("USA opacity:");
- lcd.print(usalight);
- lcd.print("%");
- EEPROM.write(8, usalight);
- }
- if (menudone == 3) {
- alarmtime = map(analogRead(potPin), 0, 1025, 1, 30); //set the new value
- lcd.print("Alarm time:");
- lcd.print(alarmtime);
- lcd.print("s");
- EEPROM.write(5, alarmtime);
- }
- if (menudone == 4) {
- timeToKnock = map(analogRead(potPin), 0, 1025, 1, 30); //set the new value
- lcd.print("Knock time:");
- lcd.print(timeToKnock);
- lcd.print("s");
- EEPROM.write(6, timeToKnock);
- }
- filldown();
- menupage = 1;
- menumode = 3; // no click
- click_sound(); // --- buzzer sound
- delay(1500);
- lcd.clear();
- }
- else if (menupage <= 2) { //ENTERING A MENU
- if (menumode != 3) {
- if (menusel == 6) {
- menumode = 0;
- click_sound(); // --- buzzer sound
- }
- if ( (menusel % 2) == 0) {
- filldown();
- }
- else {
- fillup();
- }
- delay(150);
- menupage = (menusel + 2);
- click_sound(); // --- buzzer sound
- lcd.clear();
- }
- }
- }
- //end of timeout
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement