Chirag Shah
/
ESE519_read
ESE519-Reading from mat
main.cpp@0:058183080519, 2016-10-23 (annotated)
- Committer:
- chirags
- Date:
- Sun Oct 23 21:12:10 2016 +0000
- Revision:
- 0:058183080519
Basic sensor reading
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chirags | 0:058183080519 | 1 | #include "mbed.h" |
chirags | 0:058183080519 | 2 | |
chirags | 0:058183080519 | 3 | DigitalOut select0_mux1(p24); |
chirags | 0:058183080519 | 4 | DigitalOut select1_mux1(p23); |
chirags | 0:058183080519 | 5 | DigitalOut select2_mux1(p22); |
chirags | 0:058183080519 | 6 | DigitalOut select3_mux1(p21); |
chirags | 0:058183080519 | 7 | AnalogIn analog_read_1(p20); |
chirags | 0:058183080519 | 8 | |
chirags | 0:058183080519 | 9 | int getBit(int num, int bitNo) { |
chirags | 0:058183080519 | 10 | return ((num&(1<<bitNo)) > 0)?1:0; |
chirags | 0:058183080519 | 11 | } |
chirags | 0:058183080519 | 12 | |
chirags | 0:058183080519 | 13 | int main() { |
chirags | 0:058183080519 | 14 | while(1) { |
chirags | 0:058183080519 | 15 | |
chirags | 0:058183080519 | 16 | for (int i = 0; i< 16; i++) { |
chirags | 0:058183080519 | 17 | printf("Select Line: %d ", i); |
chirags | 0:058183080519 | 18 | |
chirags | 0:058183080519 | 19 | // This code will select the select lines on the mbed |
chirags | 0:058183080519 | 20 | select0_mux1 = getBit(i, 0); |
chirags | 0:058183080519 | 21 | select1_mux1 = getBit(i, 1); |
chirags | 0:058183080519 | 22 | select2_mux1 = getBit(i, 2); |
chirags | 0:058183080519 | 23 | select3_mux1 = getBit(i, 3); |
chirags | 0:058183080519 | 24 | wait(0.01); |
chirags | 0:058183080519 | 25 | printf("Analog Read Value: %f\n ", analog_read_1.read()); |
chirags | 0:058183080519 | 26 | wait(3); |
chirags | 0:058183080519 | 27 | } |
chirags | 0:058183080519 | 28 | } |
chirags | 0:058183080519 | 29 | } |