The Code Repository for the REV0 Steering Wheel.
Dependencies: CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses
Fork of REVO_Updated_Steering by
demo.h@36:8544a8900884, 2015-01-29 (annotated)
- Committer:
- tmccurbin
- Date:
- Thu Jan 29 04:27:19 2015 +0000
- Revision:
- 36:8544a8900884
- Child:
- 42:701df58e923a
MAJOR UPDATE; New libraries added for screens, buffers, & CAN addresses.; CAN data displays in real-time.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tmccurbin | 36:8544a8900884 | 1 | // FORMAT_CODE_START |
tmccurbin | 36:8544a8900884 | 2 | // FORMAT_CODE_START |
tmccurbin | 36:8544a8900884 | 3 | #include "Steering.h" |
tmccurbin | 36:8544a8900884 | 4 | |
tmccurbin | 36:8544a8900884 | 5 | // Macro for printing to screen; Where y is the start poition of the text, and y2 is the start position of the variable |
tmccurbin | 36:8544a8900884 | 6 | #define PUT2SCREEN(string, var, unit, x, y, y2) display.PutString(x, y, string); display.PutString(x, y2, var); display.PutString(x,y2+15,unit); |
tmccurbin | 36:8544a8900884 | 7 | |
tmccurbin | 36:8544a8900884 | 8 | unsigned int x = 0; |
tmccurbin | 36:8544a8900884 | 9 | unsigned int x_old = 0; |
tmccurbin | 36:8544a8900884 | 10 | unsigned int x_new; |
tmccurbin | 36:8544a8900884 | 11 | int diff = x_new-x_old; |
tmccurbin | 36:8544a8900884 | 12 | int threshold = 1; |
tmccurbin | 36:8544a8900884 | 13 | float y = 0.0; |
tmccurbin | 36:8544a8900884 | 14 | |
tmccurbin | 36:8544a8900884 | 15 | void update_x(void const *args) |
tmccurbin | 36:8544a8900884 | 16 | { |
tmccurbin | 36:8544a8900884 | 17 | while (1) { |
tmccurbin | 36:8544a8900884 | 18 | x++; |
tmccurbin | 36:8544a8900884 | 19 | wait_ms(1); //I added this because the microcontroller was operating so fast that you couldn't read the numbers. |
tmccurbin | 36:8544a8900884 | 20 | if (x >= 16000) { |
tmccurbin | 36:8544a8900884 | 21 | x = 0; |
tmccurbin | 36:8544a8900884 | 22 | } |
tmccurbin | 36:8544a8900884 | 23 | |
tmccurbin | 36:8544a8900884 | 24 | x_new = x; |
tmccurbin | 36:8544a8900884 | 25 | diff = x_new - x_old; |
tmccurbin | 36:8544a8900884 | 26 | } |
tmccurbin | 36:8544a8900884 | 27 | } |
tmccurbin | 36:8544a8900884 | 28 | |
tmccurbin | 36:8544a8900884 | 29 | void update_y(void const *args) |
tmccurbin | 36:8544a8900884 | 30 | { |
tmccurbin | 36:8544a8900884 | 31 | while(1) { |
tmccurbin | 36:8544a8900884 | 32 | y = y + 0.000001; |
tmccurbin | 36:8544a8900884 | 33 | if (y >= 1.0) { |
tmccurbin | 36:8544a8900884 | 34 | y = 0; |
tmccurbin | 36:8544a8900884 | 35 | |
tmccurbin | 36:8544a8900884 | 36 | } |
tmccurbin | 36:8544a8900884 | 37 | } |
tmccurbin | 36:8544a8900884 | 38 | |
tmccurbin | 36:8544a8900884 | 39 | } |
tmccurbin | 36:8544a8900884 | 40 | |
tmccurbin | 36:8544a8900884 | 41 | AnalogOut ledBar(p18); |
tmccurbin | 36:8544a8900884 | 42 | |
tmccurbin | 36:8544a8900884 | 43 | |
tmccurbin | 36:8544a8900884 | 44 | int main() |
tmccurbin | 36:8544a8900884 | 45 | { |
tmccurbin | 36:8544a8900884 | 46 | wait(1); |
tmccurbin | 36:8544a8900884 | 47 | |
tmccurbin | 36:8544a8900884 | 48 | Thread thread(update_x); |
tmccurbin | 36:8544a8900884 | 49 | |
tmccurbin | 36:8544a8900884 | 50 | Thread thread2(update_y); |
tmccurbin | 36:8544a8900884 | 51 | |
tmccurbin | 36:8544a8900884 | 52 | |
tmccurbin | 36:8544a8900884 | 53 | display.PutString(0, 42, "Live Test"); |
tmccurbin | 36:8544a8900884 | 54 | |
tmccurbin | 36:8544a8900884 | 55 | PUT2SCREEN("CAN-1:", CAN1Buffer, "", 3, 0, 30); |
tmccurbin | 36:8544a8900884 | 56 | PUT2SCREEN("CAN-2:", CAN2Buffer, "", 3, 77,107); |
tmccurbin | 36:8544a8900884 | 57 | |
tmccurbin | 36:8544a8900884 | 58 | |
tmccurbin | 36:8544a8900884 | 59 | |
tmccurbin | 36:8544a8900884 | 60 | PUT2SCREEN("CAN-3:", CAN3Buffer, "", 5, 0, 30); |
tmccurbin | 36:8544a8900884 | 61 | PUT2SCREEN("CAN-4:", CAN4Buffer, "", 5, 77,107); |
tmccurbin | 36:8544a8900884 | 62 | |
tmccurbin | 36:8544a8900884 | 63 | while (1) { |
tmccurbin | 36:8544a8900884 | 64 | printf("x = %d y = %f\n", x, y); //9600 baud (default) |
tmccurbin | 36:8544a8900884 | 65 | |
tmccurbin | 36:8544a8900884 | 66 | ledBar = y*(2.7/3.3); |
tmccurbin | 36:8544a8900884 | 67 | |
tmccurbin | 36:8544a8900884 | 68 | if (abs(diff) >= threshold) { |
tmccurbin | 36:8544a8900884 | 69 | display.GotoXY(30,24); |
tmccurbin | 36:8544a8900884 | 70 | //display.PutString(3,30, " "); |
tmccurbin | 36:8544a8900884 | 71 | display.PrintInteger(x,3,30); |
tmccurbin | 36:8544a8900884 | 72 | display.PrintInteger(x,3,107); |
tmccurbin | 36:8544a8900884 | 73 | display.PrintInteger(x,5,30); |
tmccurbin | 36:8544a8900884 | 74 | display.PrintInteger(x,5,107); |
tmccurbin | 36:8544a8900884 | 75 | x_old = x_new; |
tmccurbin | 36:8544a8900884 | 76 | } |
tmccurbin | 36:8544a8900884 | 77 | } |
tmccurbin | 36:8544a8900884 | 78 | |
tmccurbin | 36:8544a8900884 | 79 | } |
tmccurbin | 36:8544a8900884 | 80 | // FORMAT_CODE_END |
tmccurbin | 36:8544a8900884 | 81 | // FORMAT_CODE_END |