Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_PCD8544.h>
- #define STROBE_OFF 0
- #define STROBE_MODE_1 1
- #define STROBE_MODE_2 2
- #define STROBE_MODE_3 3
- char * strobeLabels[] = {"", " BRAKE", " REAR", " SOLID"};
- char * fogLabels[] = {"", " ON", " AUTO"};
- #define FOG_OFF 0
- #define FOG_ON 1
- #define FOG_AUTO 2
- Adafruit_PCD8544 display = Adafruit_PCD8544(9, 10, 11, 12, 13);
- static const unsigned char PROGMEM logo38X29_off_bmp[] =
- {
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x1,0xf0,0x3f,0x9f,0xc0,
- 0x3,0xfc,0x3f,0x9f,0xc0,
- 0x7,0xfe,0x3f,0x9f,0xc0,
- 0x7,0x9e,0x3f,0x9f,0xc0,
- 0x7,0x9e,0x3c,0x1e,0x0,
- 0x7,0x9e,0x3c,0x1e,0x0,
- 0x7,0x9e,0x3c,0x1e,0x0,
- 0x7,0x9e,0x3f,0x9f,0xc0,
- 0x7,0x9e,0x3f,0x9f,0xc0,
- 0x7,0x9e,0x3f,0x9f,0xc0,
- 0x7,0x9e,0x3f,0x9f,0xc0,
- 0x7,0x9e,0x3c,0x1e,0x0,
- 0x7,0x9e,0x3c,0x1e,0x0,
- 0x7,0x9e,0x3c,0x1e,0x0,
- 0x7,0x9e,0x3c,0x1e,0x0,
- 0x7,0xfe,0x3c,0x1e,0x0,
- 0x3,0xfc,0x3c,0x1e,0x0,
- 0x0,0xf8,0x3c,0x1e,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0
- };
- static const unsigned char PROGMEM logo38X29_fog_bmp[] =
- {
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x8,0x0,
- 0x0,0x7,0x80,0xc,0x0,
- 0x0,0x1f,0xe0,0xe,0x0,
- 0x0,0xfc,0xe0,0x6,0x0,
- 0x1,0xf0,0x70,0x3,0x0,
- 0x3,0xc0,0x33,0xff,0xc0,
- 0x7,0x0,0x33,0xff,0xc0,
- 0xe,0x0,0x30,0x3,0x0,
- 0x1c,0x0,0x30,0x6,0x0,
- 0x1c,0x0,0x30,0xe,0x0,
- 0x18,0x0,0x30,0xc,0x0,
- 0x18,0x0,0x33,0xff,0xc0,
- 0x18,0x0,0x33,0xff,0xc0,
- 0x18,0x0,0x30,0x18,0x0,
- 0x1c,0x0,0x30,0x18,0x0,
- 0xc,0x0,0x30,0x38,0x0,
- 0xe,0x0,0x30,0x30,0x0,
- 0x7,0x80,0x33,0xff,0xc0,
- 0x3,0xc0,0x33,0xff,0xc0,
- 0x1,0xf0,0x70,0x30,0x0,
- 0x0,0x7c,0xe0,0x18,0x0,
- 0x0,0x3f,0xe0,0x1c,0x0,
- 0x0,0x7,0x80,0xc,0x0,
- 0x0,0x0,0x0,0x4,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0
- };
- static const unsigned char PROGMEM logo38X29_fog2_bmp[] =
- {
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x8,0x0,
- 0x0,0x7,0x80,0xc,0x0,
- 0x0,0x1f,0xe0,0xe,0x0,
- 0x0,0xff,0xe0,0x6,0x0,
- 0x1,0xff,0xf0,0x3,0x0,
- 0x3,0xff,0xf3,0xff,0xc0,
- 0x7,0xff,0xf3,0xff,0xc0,
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0,0x0,
- 0x0,0x0,0xfc,0x0,0x0,
- 0x0,0x1,0xfe,0x0,0x0,
- 0x0,0x1,0xff,0x0,0x0,
- 0x0,0x1,0xef,0x0,0x0,
- 0x0,0x1,0xef,0x0,0x0,
- 0x0,0x0,0xf,0x0,0x0,
- 0x0,0x0,0x3f,0x0,0x0,
- 0x0,0x0,0x3c,0x0,0x0,
- 0x0,0x0,0x3f,0x0,0x0,
- 0x0,0x0,0xf,0x0,0x0,
- 0x0,0x1,0xef,0x0,0x0,
- 0x0,0x1,0xef,0x0,0x0,
- 0x0,0x1,0xef,0x0,0x0,
- 0x0,0x1,0xef,0x0,0x0,
- 0x0,0x1,0xef,0x0,0x0,
- 0x0,0x1,0xff,0x0,0x0,
- 0x0,0x0,0xfe,0x0,0x0,
- 0x0,0x0,0x7c,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0
- };
- void setup() {
- Serial.begin(9600);
- display.begin();
- display.setContrast(60);
- display.display(); // show splashscreen
- delay(2000);
- display.clearDisplay(); // clears the screen and buffer
- }
- // Distance bar
- void cleanDistanceBar()
- {
- display.fillRect(0, 0, display.width(), display.height()/5, 0);
- }
- void drawDistanceBar(int size)
- {
- cleanDistanceBar();
- display.fillRect(0, 0, display.width() * size / 100, display.height()/5, 1);
- display.display();
- }
- // Fog zone
- void cleanFogIcon()
- {
- display.fillRect(0, display.height()/5, (display.width() / 2) - 1,
- (display.height() * 7 / 10) - 2, 0);
- display.display();
- }
- void drawFogIcon(int mode)
- {
- cleanFogIcon();
- if (mode == FOG_OFF)
- {
- display.drawBitmap(0, display.height()/5, logo38X29_off_bmp, 38, 29, 1);
- }
- else if (mode == FOG_ON)
- {
- display.drawBitmap(0, display.height()/5, logo38X29_fog_bmp, 38, 29, 1);
- }
- else if (mode == FOG_AUTO)
- {
- display.drawBitmap(0, display.height()/5, logo38X29_fog2_bmp, 38, 29, 1);
- }
- display.display();
- }
- // Strobe zone
- void cleanStrobeIcon()
- {
- display.fillRect((display.width()/2) + 1, display.height()/5, (display.width()/2) - 1,
- (display.height() * 7 / 10) - 2, 0);
- display.display();
- }
- void drawStrobeIcon(int mode)
- {
- cleanStrobeIcon();
- if (mode == STROBE_OFF)
- {
- display.drawBitmap((display.width()/2) + 1, display.height()/5, logo38X29_off_bmp, 38, 29, 1);
- }
- else if (mode == STROBE_MODE_1)
- {
- display.drawBitmap((display.width()/2) + 1, display.height()/5, logo38X29_1_bmp, 38, 29, 1);
- }
- else if (mode == STROBE_MODE_2)
- {
- display.drawBitmap((display.width()/2) + 1, display.height()/5, logo38X29_2_bmp, 38, 29, 1);
- }
- else if (mode == STROBE_MODE_3)
- {
- display.drawBitmap((display.width()/2) + 1, display.height()/5, logo38X29_3_bmp, 38, 29, 1);
- }
- display.display();
- }
- // Divisor
- void drawIconDivisor()
- {
- display.fillRect((display.width() / 2) - 1, (display.height() / 5) + 1, 2,
- (display.height() * 7 / 10) - 3, 1);
- display.display();
- }
- // Write fog label
- void writeFogLabel(char * label)
- {
- clearFogLabel();
- display.setCursor(0, (display.height() * 8 / 10) + 3);
- display.print(label);
- display.display();
- }
- void clearFogLabel()
- {
- display.fillRect(0, (display.height() * 8 / 10) + 3, display.width() / 2, 7, 0);
- display.display();
- }
- // Write strobe label
- void writeStrobeLabel(char * label)
- {
- clearStrobeLabel();
- display.setCursor(display.width() / 2, (display.height() * 8 / 10) + 3);
- display.print(label);
- display.display();
- }
- void clearStrobeLabel()
- {
- display.fillRect(display.width() / 2, (display.height() * 8 / 10) + 3,
- display.width() / 2, 7, 0);
- display.display();
- }
- void updateLCDStrobe(int mode)
- {
- drawStrobeIcon(mode);
- writeStrobeLabel(strobeLabels[mode]);
- }
- void updateLCDFog(int mode)
- {
- drawFogIcon(mode);
- writeFogLabel(fogLabels[mode]);
- }
- void graphicsTest1(){
- int i = 0;
- drawIconDivisor();
- for (i = 0; i < 101; i++)
- {
- drawDistanceBar(i);
- }
- for (i = 0; i < 4; i++)
- {
- updateLCDStrobe(i);
- delay(1000);
- }
- for (i = 0; i < 3; i++)
- {
- updateLCDFog(i);
- delay(1000);
- }
- }
- void loop() {
- graphicsTest1();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement