![](/media/cache/group/cropped-logo_small-2_BOjObak.png.50x50_q85.png)
voor lennart
Dependencies: mbed ADS1015 USBDevice
main.cpp@1:45df6a3a9a2c, 2019-01-16 (annotated)
- Committer:
- lennartreij
- Date:
- Wed Jan 16 15:57:31 2019 +0000
- Revision:
- 1:45df6a3a9a2c
- Parent:
- 0:ce39f1aa5d6e
stable version 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RoelvdPlas | 0:ce39f1aa5d6e | 1 | //Including the needed libraries |
RoelvdPlas | 0:ce39f1aa5d6e | 2 | #include "mbed.h" |
RoelvdPlas | 0:ce39f1aa5d6e | 3 | #include "Adafruit_ADS1015.h" |
RoelvdPlas | 0:ce39f1aa5d6e | 4 | #include "USBSerial.h" |
lennartreij | 1:45df6a3a9a2c | 5 | #include "stdio.h" |
RoelvdPlas | 0:ce39f1aa5d6e | 6 | |
RoelvdPlas | 0:ce39f1aa5d6e | 7 | //Not sure if we need those? |
RoelvdPlas | 0:ce39f1aa5d6e | 8 | #define SERIAL_BAUD_RATE 115200 |
RoelvdPlas | 0:ce39f1aa5d6e | 9 | #define ADC_MAX_VALUE 2048 |
RoelvdPlas | 0:ce39f1aa5d6e | 10 | |
RoelvdPlas | 0:ce39f1aa5d6e | 11 | //Defining the I2C and Serial port connections |
RoelvdPlas | 0:ce39f1aa5d6e | 12 | I2C i2c(p28,p27); |
RoelvdPlas | 0:ce39f1aa5d6e | 13 | Serial pc(USBTX, USBRX); |
RoelvdPlas | 0:ce39f1aa5d6e | 14 | |
RoelvdPlas | 0:ce39f1aa5d6e | 15 | //Defining the goto adress for the ADC |
RoelvdPlas | 0:ce39f1aa5d6e | 16 | Adafruit_ADS1115 adc(&i2c, 0x48); |
RoelvdPlas | 0:ce39f1aa5d6e | 17 | Adafruit_ADS1115 adc2(&i2c, 0x49); |
RoelvdPlas | 0:ce39f1aa5d6e | 18 | |
RoelvdPlas | 0:ce39f1aa5d6e | 19 | //Setting i2c frequency and baudrate |
RoelvdPlas | 0:ce39f1aa5d6e | 20 | int i2c__frequency = 100000; |
RoelvdPlas | 0:ce39f1aa5d6e | 21 | int baud_rate = 115200; |
RoelvdPlas | 0:ce39f1aa5d6e | 22 | |
RoelvdPlas | 0:ce39f1aa5d6e | 23 | //Declair var |
lennartreij | 1:45df6a3a9a2c | 24 | int ledPin = 0; |
lennartreij | 1:45df6a3a9a2c | 25 | int listFSR[10] [10]; //column 0 t/m 7 - FSR data, column 8 - lap number, column 9 - posture lable |
lennartreij | 1:45df6a3a9a2c | 26 | int listPE[10] [8]; //column 0 t/m 5 - PE data, column 6 - lap number, column 7 - posture lable |
RoelvdPlas | 0:ce39f1aa5d6e | 27 | |
RoelvdPlas | 0:ce39f1aa5d6e | 28 | void setupLED(){ |
lennartreij | 1:45df6a3a9a2c | 29 | DigitalOut ledPin(LED1); |
RoelvdPlas | 0:ce39f1aa5d6e | 30 | } |
RoelvdPlas | 0:ce39f1aa5d6e | 31 | |
lennartreij | 1:45df6a3a9a2c | 32 | void introTekst(){ |
lennartreij | 1:45df6a3a9a2c | 33 | int c; |
lennartreij | 1:45df6a3a9a2c | 34 | pc.printf("\nTo start test press ENTER... \n \n"); |
lennartreij | 1:45df6a3a9a2c | 35 | pc.printf("When you have pressed enter, a 5 second countdown will begin. After this countdown, the test will begin. \n \n"); |
lennartreij | 1:45df6a3a9a2c | 36 | pc.printf("You have to follow the pattern listed below 10 times: \n"); |
lennartreij | 1:45df6a3a9a2c | 37 | pc.printf("1. Right side \n"); |
lennartreij | 1:45df6a3a9a2c | 38 | pc.printf("2. Back \n"); |
lennartreij | 1:45df6a3a9a2c | 39 | pc.printf("3. Left side \n"); |
lennartreij | 1:45df6a3a9a2c | 40 | pc.printf("4. Out of bed \n \n"); |
lennartreij | 1:45df6a3a9a2c | 41 | pc.printf("A long PIEEP indicates you to switch to the next position on the list, you have 5 seconds to switch. \n"); |
lennartreij | 1:45df6a3a9a2c | 42 | pc.printf("Two short PIEP's indicates you that the measurement has begun. Do not move during this period of 15 seconds. \n"); |
lennartreij | 1:45df6a3a9a2c | 43 | pc.printf("Three long PIEEEEP's will indicate you that the test has finished. \n \n"); |
lennartreij | 1:45df6a3a9a2c | 44 | pc.printf("Good luck!\n"); |
lennartreij | 1:45df6a3a9a2c | 45 | fflush(stdout); |
lennartreij | 1:45df6a3a9a2c | 46 | do c = getchar(); while((c != '\n') && (c != EOF)); //Press enter to continue |
lennartreij | 1:45df6a3a9a2c | 47 | pc.printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); |
RoelvdPlas | 0:ce39f1aa5d6e | 48 | } |
lennartreij | 1:45df6a3a9a2c | 49 | |
lennartreij | 1:45df6a3a9a2c | 50 | void piepLong(){ //create long piep sound one time |
lennartreij | 1:45df6a3a9a2c | 51 | ledPin = 1; |
lennartreij | 1:45df6a3a9a2c | 52 | pc.printf("PIEEEEEEEP"); |
lennartreij | 1:45df6a3a9a2c | 53 | wait_ms(1000); |
lennartreij | 1:45df6a3a9a2c | 54 | ledPin = 0; |
lennartreij | 1:45df6a3a9a2c | 55 | pc.printf("\n"); |
RoelvdPlas | 0:ce39f1aa5d6e | 56 | } |
RoelvdPlas | 0:ce39f1aa5d6e | 57 | |
lennartreij | 1:45df6a3a9a2c | 58 | void piepShort(int x){ //create short piep sound for x times |
lennartreij | 1:45df6a3a9a2c | 59 | for(int i=1; i<=x; i++){ |
lennartreij | 1:45df6a3a9a2c | 60 | ledPin = 1; |
lennartreij | 1:45df6a3a9a2c | 61 | pc.printf("PIEP "); |
lennartreij | 1:45df6a3a9a2c | 62 | wait_ms(200); |
lennartreij | 1:45df6a3a9a2c | 63 | ledPin = 0; |
lennartreij | 1:45df6a3a9a2c | 64 | } |
lennartreij | 1:45df6a3a9a2c | 65 | pc.printf("\n"); |
lennartreij | 1:45df6a3a9a2c | 66 | } |
lennartreij | 1:45df6a3a9a2c | 67 | |
lennartreij | 1:45df6a3a9a2c | 68 | void countDown(){ //countdown from 5. makes short piep sound every second |
lennartreij | 1:45df6a3a9a2c | 69 | for(int i=5; i>=1; i--){ |
lennartreij | 1:45df6a3a9a2c | 70 | ledPin = 1; |
lennartreij | 1:45df6a3a9a2c | 71 | pc.printf("%d", i); |
lennartreij | 1:45df6a3a9a2c | 72 | pc.printf("\n"); |
lennartreij | 1:45df6a3a9a2c | 73 | wait_ms(500); |
lennartreij | 1:45df6a3a9a2c | 74 | ledPin = 0; |
lennartreij | 1:45df6a3a9a2c | 75 | wait_ms(500); |
lennartreij | 1:45df6a3a9a2c | 76 | } |
lennartreij | 1:45df6a3a9a2c | 77 | } |
lennartreij | 1:45df6a3a9a2c | 78 | |
RoelvdPlas | 0:ce39f1aa5d6e | 79 | int main() { |
lennartreij | 1:45df6a3a9a2c | 80 | pc.baud(baud_rate); |
lennartreij | 1:45df6a3a9a2c | 81 | introTekst(); //explaination screen about the test |
lennartreij | 1:45df6a3a9a2c | 82 | countDown(); //5 seconds countdown |
RoelvdPlas | 0:ce39f1aa5d6e | 83 | |
lennartreij | 1:45df6a3a9a2c | 84 | for(int i=1; i<=10; i++){ //10 times loop |
lennartreij | 1:45df6a3a9a2c | 85 | pc.printf("Lap "); //print lap number |
lennartreij | 1:45df6a3a9a2c | 86 | pc.printf("%d", i); //print lap number |
lennartreij | 1:45df6a3a9a2c | 87 | pc.printf("\n"); //print lap number |
lennartreij | 1:45df6a3a9a2c | 88 | |
lennartreij | 1:45df6a3a9a2c | 89 | piepLong(); //right side signal |
lennartreij | 1:45df6a3a9a2c | 90 | wait_ms(5000); //time for turning |
lennartreij | 1:45df6a3a9a2c | 91 | piepShort(2); //create short piep sound two times |
lennartreij | 1:45df6a3a9a2c | 92 | pc.printf("collect data right side\n"); //extra information for testing |
lennartreij | 1:45df6a3a9a2c | 93 | //code collect data |
lennartreij | 1:45df6a3a9a2c | 94 | wait_ms(5000); //time for collecting data |
lennartreij | 1:45df6a3a9a2c | 95 | // end of placeholder collect data code |
lennartreij | 1:45df6a3a9a2c | 96 | |
lennartreij | 1:45df6a3a9a2c | 97 | piepLong(); //back side signal |
lennartreij | 1:45df6a3a9a2c | 98 | wait_ms(5000); //time for turning |
lennartreij | 1:45df6a3a9a2c | 99 | piepShort(2); //creat short piep sound two times |
lennartreij | 1:45df6a3a9a2c | 100 | pc.printf("collect data back side\n"); //extra information for testing |
lennartreij | 1:45df6a3a9a2c | 101 | //code collect data |
lennartreij | 1:45df6a3a9a2c | 102 | wait_ms(5000); //time for collecting data |
lennartreij | 1:45df6a3a9a2c | 103 | // end of placeholder collect data code |
RoelvdPlas | 0:ce39f1aa5d6e | 104 | |
lennartreij | 1:45df6a3a9a2c | 105 | piepLong(); //left side signal |
lennartreij | 1:45df6a3a9a2c | 106 | wait_ms(5000); //time for turning |
lennartreij | 1:45df6a3a9a2c | 107 | piepShort(2); //creat short piep sound two times |
lennartreij | 1:45df6a3a9a2c | 108 | pc.printf("collect data left side\n"); //extra information for testing |
lennartreij | 1:45df6a3a9a2c | 109 | //code collect data |
lennartreij | 1:45df6a3a9a2c | 110 | wait_ms(5000); //time for collecting data |
lennartreij | 1:45df6a3a9a2c | 111 | // end of placeholder collect data code |
lennartreij | 1:45df6a3a9a2c | 112 | |
lennartreij | 1:45df6a3a9a2c | 113 | piepLong(); //out of bed signal |
lennartreij | 1:45df6a3a9a2c | 114 | wait_ms(5000); //time for turning |
lennartreij | 1:45df6a3a9a2c | 115 | piepShort(2); //creat short piep sound two times |
lennartreij | 1:45df6a3a9a2c | 116 | pc.printf("collect data out of bed\n"); //extra information for testing |
lennartreij | 1:45df6a3a9a2c | 117 | //code collect data |
lennartreij | 1:45df6a3a9a2c | 118 | wait_ms(5000); //time for collecting data |
lennartreij | 1:45df6a3a9a2c | 119 | // end of placeholder collect data code |
lennartreij | 1:45df6a3a9a2c | 120 | } |
lennartreij | 1:45df6a3a9a2c | 121 | |
lennartreij | 1:45df6a3a9a2c | 122 | piepLong(); //final piep sounds, signal that test has finished |
lennartreij | 1:45df6a3a9a2c | 123 | piepLong(); //final piep sounds |
lennartreij | 1:45df6a3a9a2c | 124 | piepLong(); //final piep sounds |
lennartreij | 1:45df6a3a9a2c | 125 | |
RoelvdPlas | 0:ce39f1aa5d6e | 126 | return 0; |
RoelvdPlas | 0:ce39f1aa5d6e | 127 | } |