Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MMA8451Q Servo mbed
main.cpp@1:e3a0298156ed, 2016-02-26 (annotated)
- Committer:
- fdopc
- Date:
- Fri Feb 26 16:12:43 2016 +0000
- Revision:
- 1:e3a0298156ed
- Parent:
- 0:c44933f78370
- Child:
- 2:d07fe9f3d109
ss
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| fdopc | 0:c44933f78370 | 1 | #include "mbed.h" |
| fdopc | 0:c44933f78370 | 2 | #include "MMA8451Q.h" |
| fdopc | 0:c44933f78370 | 3 | |
| fdopc | 0:c44933f78370 | 4 | #include "tsi_sensor.h" |
| fdopc | 0:c44933f78370 | 5 | #include "Servo.h" |
| fdopc | 0:c44933f78370 | 6 | |
| fdopc | 0:c44933f78370 | 7 | |
| fdopc | 0:c44933f78370 | 8 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
| fdopc | 0:c44933f78370 | 9 | PinName const SDA = PTE25; |
| fdopc | 0:c44933f78370 | 10 | PinName const SCL = PTE24; |
| fdopc | 0:c44933f78370 | 11 | #elif defined (TARGET_KL05Z) |
| fdopc | 0:c44933f78370 | 12 | PinName const SDA = PTB4; |
| fdopc | 0:c44933f78370 | 13 | PinName const SCL = PTB3; |
| fdopc | 0:c44933f78370 | 14 | #elif defined (TARGET_K20D50M) |
| fdopc | 0:c44933f78370 | 15 | PinName const SDA = PTB1; |
| fdopc | 0:c44933f78370 | 16 | PinName const SCL = PTB0; |
| fdopc | 0:c44933f78370 | 17 | #else |
| fdopc | 0:c44933f78370 | 18 | #error TARGET NOT DEFINED |
| fdopc | 0:c44933f78370 | 19 | #endif |
| fdopc | 0:c44933f78370 | 20 | |
| fdopc | 0:c44933f78370 | 21 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
| fdopc | 0:c44933f78370 | 22 | /* This defines will be replaced by PinNames soon */ |
| fdopc | 0:c44933f78370 | 23 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
| fdopc | 0:c44933f78370 | 24 | #define ELEC0 9 |
| fdopc | 0:c44933f78370 | 25 | #define ELEC1 10 |
| fdopc | 0:c44933f78370 | 26 | #elif defined (TARGET_KL05Z) |
| fdopc | 0:c44933f78370 | 27 | #define ELEC0 9 |
| fdopc | 0:c44933f78370 | 28 | #define ELEC1 8 |
| fdopc | 0:c44933f78370 | 29 | #else |
| fdopc | 0:c44933f78370 | 30 | #error TARGET NOT DEFINED |
| fdopc | 0:c44933f78370 | 31 | #endif |
| fdopc | 0:c44933f78370 | 32 | |
| fdopc | 0:c44933f78370 | 33 | |
| fdopc | 0:c44933f78370 | 34 | |
| fdopc | 0:c44933f78370 | 35 | int main(void) |
| fdopc | 0:c44933f78370 | 36 | { |
| fdopc | 0:c44933f78370 | 37 | float TSILec; |
| fdopc | 0:c44933f78370 | 38 | float x, y, z; |
| fdopc | 0:c44933f78370 | 39 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
| fdopc | 0:c44933f78370 | 40 | PwmOut red(LED_RED); |
| fdopc | 0:c44933f78370 | 41 | PwmOut green(LED_GREEN); |
| fdopc | 0:c44933f78370 | 42 | PwmOut blue(LED_BLUE); |
| fdopc | 0:c44933f78370 | 43 | Servo Motor1(PTC9); |
| fdopc | 0:c44933f78370 | 44 | TSIAnalogSlider tsi(ELEC0, ELEC1, 40); |
| fdopc | 0:c44933f78370 | 45 | |
| fdopc | 0:c44933f78370 | 46 | while (true) { |
| fdopc | 0:c44933f78370 | 47 | //Check Touch Press |
| fdopc | 0:c44933f78370 | 48 | if(tsi.readPercentage()>0.001) { |
| fdopc | 0:c44933f78370 | 49 | TSILec=tsi.readPercentage(); |
| fdopc | 0:c44933f78370 | 50 | if(TSILec<0.25) { |
| fdopc | 0:c44933f78370 | 51 | red=1; |
| fdopc | 0:c44933f78370 | 52 | green=1; |
| fdopc | 0:c44933f78370 | 53 | blue=1; |
| fdopc | 0:c44933f78370 | 54 | } |
| fdopc | 0:c44933f78370 | 55 | if(TSILec>0.25 && TSILec<0.5) { |
| fdopc | 0:c44933f78370 | 56 | red=1; |
| fdopc | 0:c44933f78370 | 57 | green=1; |
| fdopc | 0:c44933f78370 | 58 | blue=0; |
| fdopc | 0:c44933f78370 | 59 | } |
| fdopc | 0:c44933f78370 | 60 | Motor1=TSILec; //Assign touch read to motor |
| fdopc | 0:c44933f78370 | 61 | wait(0.1); |
| fdopc | 0:c44933f78370 | 62 | } |
| fdopc | 0:c44933f78370 | 63 | //Read Accel |
| fdopc | 1:e3a0298156ed | 64 | else{ |
| fdopc | 1:e3a0298156ed | 65 | x=acc.getAccX(); |
| fdopc | 0:c44933f78370 | 66 | y=acc.getAccY(); |
| fdopc | 0:c44933f78370 | 67 | z=acc.getAccZ(); |
| fdopc | 0:c44933f78370 | 68 | red=x; |
| fdopc | 0:c44933f78370 | 69 | green=y; |
| fdopc | 0:c44933f78370 | 70 | blue=z; |
| fdopc | 1:e3a0298156ed | 71 | } |
| fdopc | 0:c44933f78370 | 72 | } |
| fdopc | 0:c44933f78370 | 73 | } |
| fdopc | 0:c44933f78370 | 74 | |
| fdopc | 0:c44933f78370 | 75 |