Plz
Dependencies: mbed CANMsg Adafruit_LEDBackpack
Diff: main.cpp
- Revision:
- 10:ea96b4c09854
- Parent:
- 9:42ded201dcdd
- Child:
- 11:6d6e8aea3112
diff -r 42ded201dcdd -r ea96b4c09854 main.cpp --- a/main.cpp Mon Aug 05 22:23:17 2019 +0000 +++ b/main.cpp Fri Aug 16 16:01:22 2019 +0000 @@ -32,7 +32,7 @@ const uint16_t SIGNAL_ID = 0x501; const uint16_t BUS_ID = 0x502; -const uint8_t DISPLAY_ADDR = 0x70; +//const uint8_t DISPLAY_ADDR = 0x70; char counter = 0; Serial pc(USBTX, USBRX); // tx, rx @@ -78,6 +78,73 @@ */ //====================================================================== +void displayDigit(uint8_t digit, uint8_t position) +{ + // if (position > 4) +// {} + //printf("digit = %d\t position = %d\r\n", digit, position); + if (digit > 9) { + display.displaybuffer[position] = 0; + } else if (digit == 0) { + display.displaybuffer[position] = 63; + } else if (digit == 1) { + display.displaybuffer[position] = 48; + } else if (digit == 2) { + display.displaybuffer[position] = 91; + } else if (digit == 3) { + display.displaybuffer[position] = 79; + } else if (digit == 4) { + display.displaybuffer[position] = 102; + } else if (digit == 5) { + display.displaybuffer[position] = 109; + } else if (digit == 6) { + display.displaybuffer[position] = 125; + } else if (digit == 7) { + display.displaybuffer[position] = 7; + } else if (digit == 8) { + display.displaybuffer[position] = 127; + } else if (digit == 9) { + display.displaybuffer[position] = 103; + } + timer.start(); + display.writeDisplay(); + timer.stop(); + printf("Time to writeDisplay() is %dus\r\n", timer.read_us()); + timer.reset(); +} + +void displayNumber(uint8_t number, bool position) +{ + //timer.start(); + for (int n = 0; n < 100; (n = n + 10)) + { + if (number >= n && number < n + 10) + { + dig1 = n/10; + dig2 = number - n; + } + } + + if (number > 99) + {dig1 = 0; + dig2 = 0;} + + if (position) + { + displayDigit(dig1, 3); + displayDigit(dig2, 4); + } + else if (!position) + { + displayDigit(dig1, 0); + displayDigit(dig2, 1); + } + //timer.stop(); + //printf("time taken to print number %d is %dus\r\n", number, timer.read_us()); + //timer.reset(); +} + + void flash(int light) //Turns on one of the 4 mbed LEDs { if (light == 1) {debug1 = 1; @@ -156,27 +223,8 @@ rev.mode(PullUp); brake.mode(PullUp); accel.mode(PullUp); - - -// display.begin(DISPLAY_ADDR); -// for (int n = 0; n<16; n++) -// { -// display.setBrightness(n); -// for (int i = 0; i<10; i++) -// { -// display.displaybuffer[0] = i; -// display.displaybuffer[1] = i; -// display.displaybuffer[2] = 0; -// display.displaybuffer[3] = 0; -// display.displaybuffer[4] = 0; -// display.displaybuffer[5] = 0; -// display.displaybuffer[6] = 0; -// display.displaybuffer[7] = 0; -// display.writeDisplay(); -// wait(0.5); -// } -// } - + display.begin(DISPLAY_ADDR); + display.setBrightness(10); //pc.printf("-------------------------------------\r\n"); //printf("Attempting to send a CAN message\n"); @@ -187,11 +235,14 @@ //curr_val = 0.2; //speed_val = 5.0; + curr_reading = currentPot.read(); speed_reading = speedPot.read(); speed_reading_ms = speed_reading * 30; speed_reading_kmh = speed_reading_ms*3.6; + + bool ignition_reading = ignition.read(); bool regen_reading = regen.read(); bool rev_reading = rev.read(); @@ -204,6 +255,7 @@ //pc.printf("Regen reading: %d\r\n", regen_reading); //pc.printf("Forward/reverse reading: %d\r\n", rev_reading); //pc.printf("Brake reading: %d\r\n", brake_reading); + //flash(1); //pc.printf("Accelerator reading: %d\r\n\r\n", accel_reading); //wait(2);