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: tsi_sensor MMA8451Q
Revision 3:9262b505d7a8, committed 2020-06-14
- Comitter:
- Pythia
- Date:
- Sun Jun 14 20:35:55 2020 +0000
- Parent:
- 2:fbbe69228109
- Commit message:
- Working version
Changed in this revision
LED_line.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/LED_line.h Sat Jun 13 23:01:31 2020 +0000 +++ b/LED_line.h Sun Jun 14 20:35:55 2020 +0000 @@ -6,11 +6,11 @@ //#define L_CYCLE 2400 #define L_CYCLE 1000 -#define L_LED_OFF ((unsigned long int)(0.002*L_CYCLE)) +#define L_LED_OFF ((unsigned long int)(0.003*L_CYCLE)) #define L_LED_ON ((unsigned long int)(0.100*L_CYCLE)) -#define RAMP_SLOPE 20 -#define ON_TIMEOUT 1000 +#define RAMP_SLOPE 2 +#define ON_TIMEOUT 2000 class LED_line
--- a/main.cpp Sat Jun 13 23:01:31 2020 +0000 +++ b/main.cpp Sun Jun 14 20:35:55 2020 +0000 @@ -1,6 +1,6 @@ #include "mbed.h" #include "tsi_sensor.h" -#include "MMA8451Q.h" +//#include "MMA8451Q.h" #include "LED_line.h" /* This defines will be replaced by PinNames soon */ @@ -14,53 +14,58 @@ #error TARGET NOT DEFINED #endif -#if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) - PinName const SDA = PTE25; - PinName const SCL = PTE24; -#elif defined (TARGET_KL05Z) - PinName const SDA = PTB4; - PinName const SCL = PTB3; -#elif defined (TARGET_K20D50M) - PinName const SDA = PTB1; - PinName const SCL = PTB0; -#else - #error TARGET NOT DEFINED -#endif +//#if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) +// PinName const SDA = PTE25; +// PinName const SCL = PTE24; +//#elif defined (TARGET_KL05Z) +// PinName const SDA = PTB4; +// PinName const SCL = PTB3; +//#elif defined (TARGET_K20D50M) +// PinName const SDA = PTB1; +// PinName const SCL = PTB0; +//#else +// #error TARGET NOT DEFINED +//#endif -#define MMA8451_I2C_ADDRESS (0x1d<<1) +//#define MMA8451_I2C_ADDRESS (0x1d<<1) Thread thread_run(osPriorityNormal); bool sym=false; bool prn=false; -#define SENSOR_LIMIT 1000 +#define SENSOR_LIMIT 100 enum sensor {SENSOR_ON=1, SENSOR_OFF=0} s0=SENSOR_OFF, s1=SENSOR_OFF, s2=SENSOR_OFF; unsigned int s0_counter=0, s1_counter=0, s2_counter=0; -DigitalIn sens_0(PTC1); -DigitalIn sens_1(PTC2); -DigitalIn sens_2(PTB3); +// PTC1, PTC2, PTB3 +DigitalIn sens_0(PTC2); +DigitalIn sens_1(PTB3); +DigitalIn sens_2(PTC1); LED_line l1 (PTB0, L_LED_OFF, L_LED_ON, L_CYCLE, false); LED_line l2 (PTB1, L_LED_OFF, L_LED_ON, L_CYCLE, true); -LED_line led_green(LED_GREEN, L_LED_OFF, L_LED_ON, L_CYCLE, false); -LED_line led_red(LED_RED, L_LED_OFF, L_LED_ON, L_CYCLE, true); -LED_line led_blue(LED_BLUE, L_LED_OFF, L_LED_ON, L_CYCLE, false); +//LED_line led_green(LED_GREEN, L_LED_OFF, L_LED_ON, L_CYCLE, false); +//LED_line led_red(LED_RED, L_LED_OFF, L_LED_ON, L_CYCLE, true); +//LED_line led_blue(LED_BLUE, L_LED_OFF, L_LED_ON, L_CYCLE, false); + +DigitalOut led_red(LED_RED, LED_OFF); +DigitalOut led_green(LED_GREEN, LED_OFF); +DigitalOut led_blue(LED_BLUE, LED_OFF); TSIAnalogSlider tsi(ELEC0, ELEC1, 40); -MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); +//MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); -float x, y, z; +//float x, y, z; float p; uint32_t d; inline void measure_once(void) { - x = acc.getAccX(); - y = acc.getAccY(); - z = acc.getAccZ(); +// x = acc.getAccX(); +// y = acc.getAccY(); +// z = acc.getAccZ(); p = tsi.readPercentage(); d = tsi.readDistance(); @@ -140,24 +145,28 @@ prn = !prn; ThisThread::sleep_for(1000); } + + led_red = (s0==SENSOR_ON)?LED_ON:LED_OFF; + led_green = (s1==SENSOR_ON)?LED_ON:LED_OFF; + led_blue = (s2==SENSOR_ON)?LED_ON:LED_OFF; } inline void action_once(void) { if (s0 == SENSOR_ON) { - led_green.light(); +// led_green.light(); l1.light(); } if (s1 == SENSOR_ON) { - led_red.light(); +// led_red.light(); l1.light(); l2.light(); } if (s2 == SENSOR_ON) { - led_blue.light(); +// led_blue.light(); l2.light(); } } @@ -172,12 +181,12 @@ printf("S2=%1d ", s2); printf("l1=%5d ", (int)l1.level()); printf("l2=%5d ", (int)l2.level()); - printf("R=%5d ", (int)led_red.level()); - printf("G=%5d ", (int)led_green.level()); - printf("B=%5d ", (int)led_blue.level()); +// printf("R=%5d ", (int)led_red.level()); +// printf("G=%5d ", (int)led_green.level()); +// printf("B=%5d ", (int)led_blue.level()); printf("s:%5.2f ", p); printf("d:%2dmm ", d); - printf("X: %1.2f, Y: %1.2f, Z: %1.2f\r\n", x, y, z); +// printf("X: %1.2f, Y: %1.2f, Z: %1.2f", x, y, z); printf("\r\n"); } } @@ -205,9 +214,9 @@ l1.LED_run(); l2.LED_run(); - led_green.LED_run(); - led_red.LED_run(); - led_blue.LED_run(); +// led_green.LED_run(); +// led_red.LED_run(); +// led_blue.LED_run(); ThisThread::yield(); } }