Interactive Device Design
/
LaTE_connectivity_indication_prototype
Code for one-to-one connectivity testing
main.cpp@0:60658097abea, 2014-11-03 (annotated)
- Committer:
- fil
- Date:
- Mon Nov 03 16:56:02 2014 +0000
- Revision:
- 0:60658097abea
one to one connectivity test.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fil | 0:60658097abea | 1 | #include "mbed.h" |
fil | 0:60658097abea | 2 | #include "USBKeyboard.h" |
fil | 0:60658097abea | 3 | |
fil | 0:60658097abea | 4 | SPI spi(PTD2, PTD3, PTD1); // mosi, miso, sclk |
fil | 0:60658097abea | 5 | DigitalOut csADC(PTD0); // chip select for the ADC |
fil | 0:60658097abea | 6 | DigitalOut csDAC(PTD5); // chip select for the DAC |
fil | 0:60658097abea | 7 | AnalogOut test_out(PTE30); // analog out |
fil | 0:60658097abea | 8 | AnalogIn test_in(PTB0); // analog in |
fil | 0:60658097abea | 9 | USBKeyboard keyboard; |
fil | 0:60658097abea | 10 | |
fil | 0:60658097abea | 11 | PwmOut rled(LED_RED); |
fil | 0:60658097abea | 12 | //PwmOut gled(LED_GREEN); |
fil | 0:60658097abea | 13 | //PwmOut bled(LED_BLUE); |
fil | 0:60658097abea | 14 | |
fil | 0:60658097abea | 15 | int main() { |
fil | 0:60658097abea | 16 | |
fil | 0:60658097abea | 17 | rled = 1.0; |
fil | 0:60658097abea | 18 | //spi.format(8,0); |
fil | 0:60658097abea | 19 | //spi.frequency(1000000); |
fil | 0:60658097abea | 20 | |
fil | 0:60658097abea | 21 | csADC = 1; |
fil | 0:60658097abea | 22 | csDAC = 1; |
fil | 0:60658097abea | 23 | test_sig = 0.1; |
fil | 0:60658097abea | 24 | wait(0.1); |
fil | 0:60658097abea | 25 | csDAC = 0; |
fil | 0:60658097abea | 26 | int intermediary = spi.write(0xFF); |
fil | 0:60658097abea | 27 | wait(0.01); |
fil | 0:60658097abea | 28 | csDAC = 1; |
fil | 0:60658097abea | 29 | csADC = 0; |
fil | 0:60658097abea | 30 | int out = spi.write(0x00); |
fil | 0:60658097abea | 31 | csADC = 1; |
fil | 0:60658097abea | 32 | test_out.write(0.01); |
fil | 0:60658097abea | 33 | |
fil | 0:60658097abea | 34 | while(1) { |
fil | 0:60658097abea | 35 | //test_out.write(0.01); |
fil | 0:60658097abea | 36 | //keyboard.printf("%f ",test_in.read()); |
fil | 0:60658097abea | 37 | //keyboard.printf("%f \n",test_out.read()); |
fil | 0:60658097abea | 38 | float th_low = test_out.read()*0.8; |
fil | 0:60658097abea | 39 | float th_high = test_out.read()*1.2; |
fil | 0:60658097abea | 40 | if ((test_in.read() > th_low) && (test_in.read() < th_high)) |
fil | 0:60658097abea | 41 | rled = 0.0; |
fil | 0:60658097abea | 42 | else |
fil | 0:60658097abea | 43 | rled = 1.0; |
fil | 0:60658097abea | 44 | //keyboard.printf("%f ", th_low); keyboard.printf("%f ", test_in.read()); keyboard.printf("%f \n", th_high); |
fil | 0:60658097abea | 45 | wait(0.5); |
fil | 0:60658097abea | 46 | } |
fil | 0:60658097abea | 47 | } |