Chris Talbot
/
ProtoShieldPCBTest
Functional test program for the Proto Shield PCB Project
main.cpp@1:dafbcc661e0f, 2015-12-12 (annotated)
- Committer:
- TheFella
- Date:
- Sat Dec 12 15:25:37 2015 +0000
- Revision:
- 1:dafbcc661e0f
- Parent:
- 0:241b0b9f3b07
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TheFella | 0:241b0b9f3b07 | 1 | #include "mbed.h" |
TheFella | 0:241b0b9f3b07 | 2 | |
TheFella | 0:241b0b9f3b07 | 3 | #define PRESSED 0 |
TheFella | 0:241b0b9f3b07 | 4 | #define OPEN 1 |
TheFella | 0:241b0b9f3b07 | 5 | #define ON 1 |
TheFella | 0:241b0b9f3b07 | 6 | #define OFF 0 |
TheFella | 0:241b0b9f3b07 | 7 | |
TheFella | 0:241b0b9f3b07 | 8 | //DigitalOut gpo(D0); |
TheFella | 0:241b0b9f3b07 | 9 | //DigitalOut led(LED1); |
TheFella | 0:241b0b9f3b07 | 10 | |
TheFella | 1:dafbcc661e0f | 11 | |
TheFella | 0:241b0b9f3b07 | 12 | PwmOut g(LED_GREEN); |
TheFella | 0:241b0b9f3b07 | 13 | PwmOut b(LED_BLUE); |
TheFella | 0:241b0b9f3b07 | 14 | |
TheFella | 0:241b0b9f3b07 | 15 | |
TheFella | 0:241b0b9f3b07 | 16 | DigitalOut ledGrn(PTD4); |
TheFella | 0:241b0b9f3b07 | 17 | DigitalOut ledYel(PTA12); |
TheFella | 0:241b0b9f3b07 | 18 | DigitalOut ledRed(PTA4); |
TheFella | 0:241b0b9f3b07 | 19 | AnalogIn speedControl(PTB0); |
TheFella | 0:241b0b9f3b07 | 20 | |
TheFella | 0:241b0b9f3b07 | 21 | Serial pc(USBTX, USBRX); //tx, rx 1st serial port connects to the PC for debug messages |
TheFella | 0:241b0b9f3b07 | 22 | //Serial TempControllerComm(PTD3, PTD2); //tx, rx 2nd serial port connects to the temperature controller |
TheFella | 0:241b0b9f3b07 | 23 | |
TheFella | 0:241b0b9f3b07 | 24 | enum{ LOWERLIMIT, UPPERLIMIT}; // 0, 1 |
TheFella | 0:241b0b9f3b07 | 25 | |
TheFella | 0:241b0b9f3b07 | 26 | BusIn BCDswitch(PTD0, PTD1, PTD2, PTD3); |
TheFella | 0:241b0b9f3b07 | 27 | BusIn pushButtons(PTD5, PTA13, PTC9, PTC8); |
TheFella | 0:241b0b9f3b07 | 28 | |
TheFella | 0:241b0b9f3b07 | 29 | //DigitalIn channelSelect(PTD1); |
TheFella | 0:241b0b9f3b07 | 30 | |
TheFella | 0:241b0b9f3b07 | 31 | int upperLimit; |
TheFella | 0:241b0b9f3b07 | 32 | int lowerLimit; |
TheFella | 0:241b0b9f3b07 | 33 | int currentChannel; |
TheFella | 0:241b0b9f3b07 | 34 | int currentMode; |
TheFella | 0:241b0b9f3b07 | 35 | |
TheFella | 0:241b0b9f3b07 | 36 | void initializeSystem() |
TheFella | 0:241b0b9f3b07 | 37 | { |
TheFella | 0:241b0b9f3b07 | 38 | // BCDswitch.input(); //this is the equivalent of configuring a port for input |
TheFella | 0:241b0b9f3b07 | 39 | BCDswitch.mode(PullNone); // disable the internal pullups on the port |
TheFella | 0:241b0b9f3b07 | 40 | pushButtons.mode(PullNone); |
TheFella | 0:241b0b9f3b07 | 41 | //channelSelect.mode(PullNone); //channelSelect is an individual pin configured for input |
TheFella | 0:241b0b9f3b07 | 42 | |
TheFella | 0:241b0b9f3b07 | 43 | for( int i = 0; i < 4; i++) |
TheFella | 0:241b0b9f3b07 | 44 | { |
TheFella | 0:241b0b9f3b07 | 45 | ledGrn = !ledGrn; |
TheFella | 0:241b0b9f3b07 | 46 | ledYel = !ledYel; |
TheFella | 0:241b0b9f3b07 | 47 | ledRed = !ledRed; |
TheFella | 0:241b0b9f3b07 | 48 | wait(0.5); |
TheFella | 0:241b0b9f3b07 | 49 | } |
TheFella | 0:241b0b9f3b07 | 50 | } |
TheFella | 0:241b0b9f3b07 | 51 | |
TheFella | 0:241b0b9f3b07 | 52 | int main() |
TheFella | 0:241b0b9f3b07 | 53 | { |
TheFella | 0:241b0b9f3b07 | 54 | float delay = 1.0; |
TheFella | 0:241b0b9f3b07 | 55 | b = 1; |
TheFella | 0:241b0b9f3b07 | 56 | g = 1; |
TheFella | 0:241b0b9f3b07 | 57 | initializeSystem(); |
TheFella | 0:241b0b9f3b07 | 58 | while (true) { |
TheFella | 0:241b0b9f3b07 | 59 | |
TheFella | 0:241b0b9f3b07 | 60 | b = b - ( 0x0f / (~BCDswitch.read() & 0x0f)); |
TheFella | 0:241b0b9f3b07 | 61 | g = g - ( 0x0f / (~BCDswitch.read() & 0x0f)); |
TheFella | 0:241b0b9f3b07 | 62 | |
TheFella | 0:241b0b9f3b07 | 63 | |
TheFella | 0:241b0b9f3b07 | 64 | ledYel = !ledYel; |
TheFella | 0:241b0b9f3b07 | 65 | |
TheFella | 0:241b0b9f3b07 | 66 | delay = speedControl.read(); |
TheFella | 0:241b0b9f3b07 | 67 | if( (~pushButtons.read()& 0x0f) < 15 && (~pushButtons.read()& 0x0f) > 7 ) |
TheFella | 0:241b0b9f3b07 | 68 | ledRed = ON; |
TheFella | 0:241b0b9f3b07 | 69 | else |
TheFella | 0:241b0b9f3b07 | 70 | ledRed = OFF; |
TheFella | 0:241b0b9f3b07 | 71 | |
TheFella | 0:241b0b9f3b07 | 72 | if( (~pushButtons.read()& 0x0f) > 0 && (~pushButtons.read()& 0x0f) <= 8 ) |
TheFella | 0:241b0b9f3b07 | 73 | ledGrn = ON; |
TheFella | 0:241b0b9f3b07 | 74 | else |
TheFella | 0:241b0b9f3b07 | 75 | ledGrn = OFF; |
TheFella | 0:241b0b9f3b07 | 76 | |
TheFella | 0:241b0b9f3b07 | 77 | pc.printf("\033[2J"); |
TheFella | 0:241b0b9f3b07 | 78 | pc.printf("\033[H"); |
TheFella | 0:241b0b9f3b07 | 79 | pc.printf("FRDM-KL25Z Shield Test\n\r"); |
TheFella | 0:241b0b9f3b07 | 80 | pc.printf("\n\r"); |
TheFella | 0:241b0b9f3b07 | 81 | pc.printf("Delay: \t\t%f\n\r", delay); |
TheFella | 0:241b0b9f3b07 | 82 | pc.printf("Push Buttons: \t%x\n\r",(~pushButtons.read()& 0x0f) ); |
TheFella | 0:241b0b9f3b07 | 83 | pc.printf("BCD: \t\t%x\n\r", ( ~BCDswitch.read() & 0x0f) ); |
TheFella | 0:241b0b9f3b07 | 84 | pc.printf("\n\r"); |
TheFella | 0:241b0b9f3b07 | 85 | pc.printf("LEDs:\n\r"); |
TheFella | 0:241b0b9f3b07 | 86 | pc.printf("\tGreen: \t%d\n\r", ledGrn.read()); |
TheFella | 0:241b0b9f3b07 | 87 | pc.printf("\tYellow: %d\n\r", ledYel.read()); |
TheFella | 0:241b0b9f3b07 | 88 | pc.printf("\tRed: \t%d\n\r", ledRed.read()); |
TheFella | 0:241b0b9f3b07 | 89 | |
TheFella | 0:241b0b9f3b07 | 90 | |
TheFella | 0:241b0b9f3b07 | 91 | wait(delay); |
TheFella | 0:241b0b9f3b07 | 92 | |
TheFella | 0:241b0b9f3b07 | 93 | |
TheFella | 0:241b0b9f3b07 | 94 | } |
TheFella | 0:241b0b9f3b07 | 95 | } |
TheFella | 0:241b0b9f3b07 | 96 |