Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // two buttons on digital pins 7 and 9, voltage divder on pin ang0 and thermistor on pin Ang1
- // Temerature and Voltage display using i2c 0.96 inch OLED screen
- #include <SPI.h>
- #include <Wire.h>
- #include <EEPROM.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #include <Thermistor.h>
- //----OLED setup---------------------------
- #define OLED_RESET 4
- Adafruit_SSD1306 display(OLED_RESET);
- byte x0 = 60; //center of screen (pixels)
- byte y0 = 32; //center of screen
- byte r = 30; // radius of the gauge circle (pixels)
- //-----------BUTTONS-----------------------
- const byte BUTTON_PIN_A = 7; // the number of the pushbutton pin A (select
- const byte BUTTON_PIN_B = 9; // the number of the pushbutton pin B (reset)
- byte READING_A = LOW;// button A
- byte READING_B = LOW;// button B
- byte LAST_STATE_A = LOW; // the previous reading from the input pin
- byte LAST_STATE_B = LOW; // the previous reading from the input pin
- //--------------TEMP-----------------------
- Thermistor TEMP(1); // A1- TEMPERATURE probe
- byte TEMP_MAX = 0; // variable to store the max read temp.
- byte TEMPERATURE = 0; //setp TEMPERATURE
- int TEMP_SENSOR = 0;
- //--------------VOLTAGE--------------------
- byte VOLTS_PIN = 0; // the A0 pin the voltage divider from the bike is on. (12 VOLTS=1.2 VOLTS)
- double VOLTS = 0; //setup VOLTS (read pin in to this variable)
- double VOLTS_MAX = 0; // variable to store the max read VOLTS.
- double VOLTS_SENSOR = 0;
- //--------------VOLTAGE AVERAGING ARRAY-----
- const int NUM_READINGS = 20; //number of samples to read to base the AVERAGE on
- double READINGS[NUM_READINGS]; // the READINGS array from the analog input VOLTS
- int READ_INDEX = 0; // the index of the current reading
- double TOTAL = 0; // the running TOTAL
- double AVERAGE = 0; //the final AVERAGE value
- //-----------DEBOUNCE----------------------
- long LAST_DEBOUNCE = 0; // the last time the output pin was toggled
- long DEBOUNCE_DELAY = 50; // the debounce time; increase if the output flickers
- byte BUTTON_STATE_A;
- byte BUTTON_STATE_B; // the current reading from the input pin
- //-------------SCREEN NUMBER------------------
- byte SCREEN_SWITCH = 0; // switch case var. update via button A to switch display options
- //-------HIGH/LOW WARNING THERSHOLDS-----------
- byte WARNING1 = 90; //85-100? // TEMPERATURE warning thershold in deg C.
- double WARNING2 = 14.5; // high VOLTS warning thershold in VOLTS
- byte WARNINGLOW1 = 12.1; //low voltage warning thershold
- //----------EEPROM STUFF-----------------------
- unsigned long interval = 30000;//180000; // (3 mins wait time we need to wait between checking max temp/VOLTS- to save writes to eeprom.
- unsigned long previousMillis = 0; // millis() returns an unsigned long for timer checker
- byte OIL_ADDRS = 0; //address in EEPROM to store TEMPERATURE max.
- byte VOLTS_ADDRS = 1; //address in EEPROM to store VOLTS max.
- // ---------------------------------------byte array for boot image screen in .xbm array format- search adafruit gfx xbitmap for details
- static const uint8_t PROGMEM CAFE_XBM[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0xf8, 0xf1,
- 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0xe0, 0x1f,
- 0xe0, 0x03, 0xfe, 0xf3, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
- 0x0f, 0xfe, 0xe1, 0x1f, 0xe0, 0x03, 0x0f, 0x72, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xc0, 0x0e, 0xc6, 0xe3, 0x00, 0xf0, 0x07, 0x07, 0x70,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x82, 0xe3, 0x00,
- 0x70, 0x87, 0x03, 0x70, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
- 0x0e, 0x80, 0xe3, 0x0f, 0x30, 0x86, 0x03, 0xf0, 0x0f, 0x00, 0x00, 0x00,
- 0xfc, 0x00, 0x00, 0x00, 0x0e, 0x80, 0xe3, 0x1f, 0x38, 0x8e, 0x03, 0xf0,
- 0x0f, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x0e, 0xc0, 0x21, 0x3c,
- 0xf8, 0x8f, 0x03, 0x70, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00,
- 0x0e, 0xf0, 0x01, 0x38, 0xfc, 0x1f, 0x07, 0x70, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0x01, 0x00, 0x00, 0x0e, 0xf8, 0x00, 0x38, 0x1c, 0x1c, 0x0f, 0x72,
- 0x00, 0x00, 0x00, 0xf0, 0xff, 0x01, 0x00, 0x00, 0x0e, 0x7c, 0x20, 0x3c,
- 0x1c, 0x1c, 0xfe, 0xf3, 0x1f, 0x00, 0x00, 0xfe, 0xff, 0x01, 0x00, 0xc0,
- 0x7f, 0xfe, 0xe3, 0x1f, 0x0e, 0x38, 0xf8, 0xf1, 0x1f, 0x00, 0x00, 0xff,
- 0xff, 0x01, 0x00, 0xc0, 0x7f, 0xfe, 0xc3, 0x0f, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x80, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
- 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xf0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x0f, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff,
- 0x1f, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xfe, 0xff, 0x7f, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xfd, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x3f,
- 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x80, 0xff, 0x0f, 0xfe, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xcf, 0xff, 0xff, 0x1f, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
- 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x80, 0xdf, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff,
- 0xff, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xe0, 0xff, 0xff, 0xff, 0xbf, 0xc3, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xff, 0x07,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xe1, 0xff,
- 0xff, 0xc1, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0x83, 0xff, 0xff, 0xc1, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x80, 0x0f, 0xfe, 0x87, 0xff, 0xff, 0xe1, 0x0f, 0x3e,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xfe, 0xe7, 0xff,
- 0xff, 0xf3, 0x0f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
- 0x03, 0xcf, 0xff, 0xff, 0xff, 0xfb, 0x1e, 0x78, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xe0, 0x87, 0xcf, 0xff, 0xff, 0xff, 0x7b, 0x3c, 0xf0,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0x39, 0xfc, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
- 0xfe, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xfc, 0xe1, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xe0, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x3d, 0xfe, 0xe1,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf8, 0x9f, 0xff, 0xff,
- 0xff, 0x3c, 0xfe, 0xe1, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
- 0xf0, 0xff, 0xff, 0xff, 0xff, 0x3c, 0xfe, 0xe1, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xe0, 0xf0, 0xff, 0xff, 0xff, 0x73, 0x3c, 0xfc, 0xe1,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xe1, 0xff, 0xff, 0xff,
- 0x7f, 0x38, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
- 0x81, 0xc3, 0xff, 0xff, 0x3f, 0x78, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xc0, 0x03, 0xe0, 0xff, 0xff, 0x1f, 0xf8, 0x00, 0x78,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xf0, 0x01, 0x00,
- 0x00, 0xf0, 0x01, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
- 0x1f, 0xfc, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x3f, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x1f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x3f, 0x00, 0x00,
- 0x00, 0x80, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
- };
- void setup() {
- for (byte thisReading = 0; thisReading < NUM_READINGS; thisReading++) {
- READINGS[thisReading] = 0;
- }
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C -use i2c scanner sketch to find your screen location.
- display.clearDisplay();
- display.drawXBitmap(0, 0, CAFE_XBM, 128, 64, 1); // start screen logo
- display.display();
- delay(3000);
- display. fillRect( 0, 0, 128, 96, BLACK);
- display.display();
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- TEMP_MAX = EEPROM.read(0);
- VOLTS_MAX = EEPROM.read(1);
- delay(100); //sanity delay on startup to make sure EEPROM is read
- display.clearDisplay();
- }
- void loop() {
- //---------read the analog volts and temperature in----
- TEMPERATURE = TEMP.getTemp(); // read the thermistor value using the libary.
- VOLTS = analogRead(VOLTS_PIN); // read in VOLTS 0-1023 increments for 0-50 volt range.
- VOLTS = map(VOLTS, 0, 1023, 0, 500); // remap the VOLTS to a better range
- VOLTS = VOLTS / 10; // divide by ten to get 0 to 50 VOLTS again
- VOLTS = VOLTS * 1; // correction factor for the resistor divider voltage diferance
- TEMP_SENSOR = TEMPERATURE - 3; //this is the variable for oil TEMPERATURE from eeprom
- VOLTS_SENSOR = AVERAGE; // this is the VOLTS from EEPROM
- //---------------------averaging out the volts to stop jitter--
- // subtract the last reading:
- TOTAL = TOTAL - READINGS[READ_INDEX];
- // read from the sensor:
- READINGS[READ_INDEX] = VOLTS;
- // add the reading to the TOTAL:
- TOTAL = TOTAL + READINGS[READ_INDEX];
- // advance to the next position in the array:
- READ_INDEX = READ_INDEX + 1;
- // if we're at the end of the array...
- if (READ_INDEX >= NUM_READINGS) {
- // ...wrap around to the beginning:
- READ_INDEX = 0;
- }
- // calculate the AVERAGE VOLTS reading to stop jitter
- AVERAGE = TOTAL / NUM_READINGS;
- delay(1); // delay in between reads for stability
- //--------------------check for button presses and apply debounce---
- READING_B = digitalRead(BUTTON_PIN_B); // READ THE INPUT PIN
- READING_A = digitalRead(BUTTON_PIN_A);
- if (READING_A != LAST_STATE_A) {
- // reset the debouncing timer
- LAST_DEBOUNCE = millis();
- }
- if (READING_B != LAST_STATE_B) {
- // reset the debouncing timer
- LAST_DEBOUNCE = millis();
- }
- //-------create a time delay to stop the EEPROM getting written to all the time----
- if ((unsigned long)(millis() - previousMillis) >= interval) {
- previousMillis = millis();
- //---------these routines check and store the maximum values to EEPROM
- readMax(); // void to set new TEMPERATURE data and update eeprom
- readMaxV(); // void to set new max VOLTS if higher and save to eeprom
- }
- //------------------
- resetMax();// check if button B pressed and reset max values in eeprom
- SELECT_A(); // button A, change screens
- LAST_STATE_A = READING_A; // set button reaing A
- LAST_STATE_B = READING_B; // SET THE STATE OF THE BUTTON B FOR CHECKING IT LATER
- //----------------------------------------------
- //--- case switching here for different display optins.
- SELECT_A();
- switch (SCREEN_SWITCH) {
- case 0 :
- display.setTextSize(2);
- VOLTSB(0, 0, 56, 0); // display VOLTS text
- oilB(0, 48, 72, 48); // display oil text
- //display.fillRect( 0, 30, 128, 4, WHITE);
- display.drawCircle( 120, 48, 3, WHITE);
- break;
- case 1: // main display screen 1
- display.setTextSize(1);
- VOLTSA(); // display VOLTS needle
- VOLTSB(0, 0, 0, 8); // display VOLTS text
- oilA(60, 32); // display oil needle
- oilB(0, 45, 0, 55); // display oil text
- drawMAX(100, 55);
- drawMAXv(94, 0);
- MAX();//write the word max for main screen
- DRAW_FACE();//draw the dial face circles last main screen
- break;
- case 2 :
- //oil bar graph here
- display.fillRect( 0, 24, (128 / 120)*TEMPERATURE, 20, WHITE);
- for (byte i = 0; i < 7; i++) {
- display.drawLine(20 * i, 24, 20 * i, 48, BLACK);
- }
- oilB(0, 0, 72, 0); // display oil text
- break;
- case 3:
- display.fillRect( 0, 24, (128 / 24)*AVERAGE, 20, WHITE);
- for (byte i = 0; i < 7; i++) {
- display.drawLine(20 * i, 24, 20 * i, 48, BLACK);
- }
- VOLTSB(0, 0, 56, 0); // display VOLTS text
- break;
- case 4:
- display.fillRect( 0, 12, (128 / 120)*TEMPERATURE, 20, WHITE);
- for (byte i = 0; i < 7; i++) {
- display.drawLine(20 * i, 12, 20 * i, 36, BLACK);
- }
- display.fillRect( 0, 44, (128 / 24)*AVERAGE, 20, WHITE);
- for (byte i = 0; i < 7; i++) {
- display.drawLine(20 * i, 44, 20 * i, 64, BLACK);
- }
- display.setTextSize(1);
- oilB(0, 0, 72, 0); // display oil text
- VOLTSB(0, 34, 56, 34); // display VOLTS text
- break;
- case 5: // single bottom sweep temp gauge
- display.setTextSize(3);
- display.setTextColor( 1 );
- display.setCursor(46, 0);
- display.println(TEMPERATURE - 3);
- oilA(64, 60); // display oil needle
- display.drawRoundRect( 24, 24, 80, 46, 6 , WHITE);
- break;
- case 6:
- display.fillRect( 0, 0, (128 / 24)*AVERAGE, 128, WHITE);
- for (byte i = 0; i < 7; i++) {
- display.drawLine(20 * i, 0, 20 * i, 128, BLACK);
- }
- display.fillTriangle(0, 0, 0, 46, 200, 0, BLACK );
- display.setTextSize(2);
- display.setCursor(4, 4);
- VOLTSB(0, 0, 60, 0); // display oil text
- break;
- case 7:
- display.fillRect( 0, 0, (128 / 120)*TEMPERATURE - 3, 128, WHITE);
- for (byte i = 0; i < 7; i++) {
- display.drawLine(20 * i, 0, 20 * i, 128, BLACK);
- }
- display.fillTriangle(0, 0, 0, 46, 200, 0, BLACK );
- display.setTextSize(2);
- display.setCursor(4, 4);
- oilB(0, 0, 60, 0); // display oil text
- break;
- case 8 :
- display.setTextSize(1);
- display.setCursor(10, 0);
- display.setTextColor(0, 1 );
- display.println("MAX STORED VALUES");
- display.setTextColor(1 );
- display.setTextSize(2);
- VOLTSB(0, 20, 56, 20); // display VOLTS text
- oilB(0, 48, 72, 48); // display oil text
- display.fillRect( 50, 20, 82, 45, BLACK);
- drawMAX(72, 48);
- drawMAXv(56, 20);
- break;
- case 9:
- // display. fillRect( 0, 0, 128, 96, BLACK);
- display.drawXBitmap(0, 0, CAFE_XBM, 128, 64, 1);
- break;
- case 10:
- display. fillRect( 0, 0, 128, 96, BLACK);
- }
- //---------------------------------------------
- if (TEMPERATURE - 3 > WARNING1) {
- display.setTextSize(2);
- display.setTextColor(0, 1 );
- display.setCursor(8, 24);
- display.println("TEMP HIGH");
- }
- //---------------------------------------------
- if (VOLTS < WARNINGLOW1) {
- display.setTextSize(2);
- display.setTextColor(0, 1 );
- display.setCursor(8, 24);
- display.println("VOLTS LOW");
- }
- if (VOLTS > WARNING2) {
- display.setTextSize(2);
- display.setTextColor(0, 1 );
- display.setCursor(8, 24);
- display.println("VOLT HIGH");
- }
- display.display();
- display.clearDisplay();
- delay(2);
- }
- //----end main void loop
- //---------------start of function loops
- void DRAW_FACE() {
- //----center of the dial and the ring
- display.drawCircle(x0, y0, r, WHITE);
- display.fillCircle( x0, y0, 6, WHITE);
- display.fillCircle( x0, y0, 3, BLACK );
- }
- void VOLTSA() { // voltage gauge needle
- display.drawLine(x0, y0, x0 + r * sin(-135 + 2 * (VOLTS_SENSOR + 90) * 2 * 3.14 / 18), y0 - r * cos(-135 + 2 * (VOLTS_SENSOR + 90) * 2 * 3.14 / 18), WHITE);
- display.fillCircle( x0, y0, 20, BLACK);
- }
- void VOLTSB(byte x, byte y, byte x1, byte y1) { // voltage text main screen
- display.setTextColor(WHITE);
- display.setCursor(0 + x, 0 + y);
- display.println("VOLT");
- display.setCursor(0 + x1, 0 + y1);
- display.println(VOLTS_SENSOR); //set voltage var to here later
- }
- void oilA(byte x1, byte y1) { //oil gauge needle
- display.drawLine(x1, y1, x1 + r * sin(293 + 2 * (TEMP_SENSOR) * 2 * 3.14 / 360), y1 - r * cos(293 + 2 * (TEMP_SENSOR) * 2 * 3.14 / 360), WHITE);
- display.drawLine(x1 + 2, y1, x1 + r * sin(293 + 2 * (TEMP_SENSOR) * 2 * 3.14 / 360), y1 - r * cos(293 + 2 * (TEMP_SENSOR) * 2 * 3.14 / 360), WHITE);
- display.drawLine(x1 - 2, y1, x1 + r * sin(293 + 2 * (TEMP_SENSOR) * 2 * 3.14 / 360), y1 - r * cos(293 + 2 * (TEMP_SENSOR) * 2 * 3.14 / 360), WHITE);
- display.drawLine(x1, y1 + 2, x1 + r * sin(293 + 2 * (TEMP_SENSOR) * 2 * 3.14 / 360), y1 - r * cos(293 + 2 * (TEMP_SENSOR) * 2 * 3.14 / 360), WHITE);
- display.drawLine(x1, y1 - 2, x1 + r * sin(293 + 2 * (TEMP_SENSOR) * 2 * 3.14 / 360), y1 - r * cos(293 + 2 * (TEMP_SENSOR) * 2 * 3.14 / 360), WHITE);
- }
- void oilB(byte x, byte y, byte x1, byte y1) { // oil temp text main screen
- display.setTextColor(WHITE);
- display.setCursor(x, y);
- display.println("TEMP");
- display.setCursor(x1, y1);
- display.println(TEMP_SENSOR); //display TEMPERATURE
- }
- void drawMAX(byte x, byte y) {
- display.setCursor(x, y);
- display.println(TEMP_MAX);
- }
- void MAX() { //write the word MAX on screen
- display.setTextColor(WHITE);
- display.setCursor(105, 28);
- display.println("MAX");
- }
- void drawMAXv(byte x, byte y) { //draw max VOLTS on screen
- display.setCursor(x, y);
- display.println(VOLTS_MAX);
- }
- void readMax() { // Save max temperature to eeprom
- if (TEMP_SENSOR > TEMP_MAX) {
- TEMP_MAX = TEMP_SENSOR;
- EEPROM.update(OIL_ADDRS, TEMP_MAX);
- display.setCursor(50, 0);
- display.println("SAVED");
- delay(30);
- }
- }
- void readMaxV() {
- if (VOLTS > VOLTS_MAX) {
- VOLTS_MAX = VOLTS;
- EEPROM.update(VOLTS_ADDRS, VOLTS_MAX);
- display.setCursor(50, 0);
- display.println("SAVED");
- delay(300);
- }
- }
- int SELECT_A() { // Debounce and variable setting for button A
- if ((millis() - LAST_DEBOUNCE) > DEBOUNCE_DELAY) {
- if (READING_A != BUTTON_STATE_A) {
- BUTTON_STATE_A = READING_A;
- if (BUTTON_STATE_A == HIGH) {
- if (SCREEN_SWITCH < 10) {
- SCREEN_SWITCH = SCREEN_SWITCH + 1;
- }
- else {
- SCREEN_SWITCH = 0;
- }
- }
- }
- }
- }
- void resetMax() { //Reset the stored max values to zero
- if ((millis() - LAST_DEBOUNCE) > DEBOUNCE_DELAY) {
- if (READING_B != BUTTON_STATE_B) {
- BUTTON_STATE_B = READING_B;
- if (BUTTON_STATE_B == HIGH) {
- //ledState = !ledState;
- TEMP_MAX = 0;
- VOLTS_MAX = 0;
- EEPROM.update(VOLTS_ADDRS, VOLTS_MAX);
- EEPROM.update(OIL_ADDRS, TEMP_MAX);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement