Interfaçage NeoPixel Ring 12, LPRO MECSE, Arnaud A.

Dependencies:   lcd neoPixelRing12 view2 BSP_DISCO_F746NG view1 button

Committer:
Rhamao
Date:
Thu May 28 15:32:34 2020 +0000
Revision:
6:91e478ee227e
Parent:
5:e8f8a8037256
Child:
7:1887c4e4b5de
bit0() fonctionne + pour eteindre la premiere lED  faire : 24*0 + rst() + 24*0 + le reste

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:b045ca817e2c 1 #include "mbed.h"
Rhamao 6:91e478ee227e 2 #include "Thread.h"
Rhamao 6:91e478ee227e 3 #include "rtos_idle.h"
Rhamao 6:91e478ee227e 4 #include "mbed_critical.h"
Rhamao 6:91e478ee227e 5
Rhamao 6:91e478ee227e 6 #define USE_CRITICAL_SECTION_LOCK 1 // Set 0 to see race condition
Rhamao 6:91e478ee227e 7
Rhamao 6:91e478ee227e 8 InterruptIn button(USER_BUTTON)
Rhamao 6:91e478ee227e 9 ;
Rhamao 6:91e478ee227e 10 DigitalOut myled(D8);
Rhamao 6:91e478ee227e 11 DigitalOut led1(LED1);
Rhamao 6:91e478ee227e 12
Rhamao 6:91e478ee227e 13 void bit0(){
Rhamao 6:91e478ee227e 14 myled = 1;
Rhamao 6:91e478ee227e 15 wait_ns(190);
Rhamao 6:91e478ee227e 16 myled = 0;
Rhamao 6:91e478ee227e 17 wait_ns(740);
Rhamao 6:91e478ee227e 18 }
Rhamao 6:91e478ee227e 19
Rhamao 6:91e478ee227e 20 void bit1(){
Rhamao 6:91e478ee227e 21 myled = 1;
Rhamao 6:91e478ee227e 22 wait_ns(600);
Rhamao 6:91e478ee227e 23 myled = 0;
Rhamao 6:91e478ee227e 24 wait_ns(600);
Rhamao 6:91e478ee227e 25 }
Rhamao 6:91e478ee227e 26
Rhamao 6:91e478ee227e 27 void rst(){
Rhamao 6:91e478ee227e 28 myled=0;
Rhamao 6:91e478ee227e 29 wait_us(70);
Rhamao 6:91e478ee227e 30 }
Rhamao 6:91e478ee227e 31
Rhamao 6:91e478ee227e 32 void setLights(bool state, int nbOfLeds){
Rhamao 6:91e478ee227e 33 if(state){
Rhamao 6:91e478ee227e 34 for(int i=0; i<24*nbOfLeds; i++){
Rhamao 6:91e478ee227e 35 bit1();
Rhamao 6:91e478ee227e 36 }
Rhamao 6:91e478ee227e 37 }
Rhamao 6:91e478ee227e 38 else{
Rhamao 6:91e478ee227e 39 for(int i=0; i<24*nbOfLeds; i++){
Rhamao 6:91e478ee227e 40 bit0();
Rhamao 6:91e478ee227e 41 }
Rhamao 6:91e478ee227e 42 }
Rhamao 6:91e478ee227e 43 }
Rhamao 6:91e478ee227e 44
Rhamao 6:91e478ee227e 45 void pressed()
Rhamao 6:91e478ee227e 46 {
Rhamao 6:91e478ee227e 47 led1=1;
Rhamao 6:91e478ee227e 48 //rst();
Rhamao 6:91e478ee227e 49 //setLights(true, 1);
Rhamao 6:91e478ee227e 50 //setLights(false, 5);
Rhamao 6:91e478ee227e 51 //setLights(true, 1);
Rhamao 6:91e478ee227e 52 for(int i=0; i<16; i++){
Rhamao 6:91e478ee227e 53 bit0();
Rhamao 6:91e478ee227e 54 }
Rhamao 6:91e478ee227e 55 /*setLights(true, 1);
Rhamao 6:91e478ee227e 56 setLights(false, 1);
Rhamao 6:91e478ee227e 57 setLights(true, 1);*/
Rhamao 6:91e478ee227e 58 rst();
Rhamao 6:91e478ee227e 59
Rhamao 6:91e478ee227e 60 }
Rhamao 6:91e478ee227e 61
Rhamao 6:91e478ee227e 62 void released()
Rhamao 6:91e478ee227e 63
Rhamao 6:91e478ee227e 64 {
Rhamao 6:91e478ee227e 65 led1=0;
Rhamao 6:91e478ee227e 66 }
Rhamao 6:91e478ee227e 67
bcostm 0:b045ca817e2c 68
bcostm 0:b045ca817e2c 69 int main()
Jerome Coutant 5:e8f8a8037256 70 {
Rhamao 6:91e478ee227e 71 int i=0;
Rhamao 6:91e478ee227e 72 button.rise(&pressed);
Rhamao 6:91e478ee227e 73 button.fall(&released);
Rhamao 6:91e478ee227e 74 /*while(1){
Rhamao 6:91e478ee227e 75 myled = 1;
Rhamao 6:91e478ee227e 76 wait_ns(350);
Rhamao 6:91e478ee227e 77 myled = 0;
Rhamao 6:91e478ee227e 78 }*/
Rhamao 6:91e478ee227e 79 //while(1){
Rhamao 6:91e478ee227e 80 //CriticalSectionLock lock;
Rhamao 6:91e478ee227e 81 //bit0();
Rhamao 6:91e478ee227e 82 //CriticalSectionLock unlock;
Rhamao 6:91e478ee227e 83 setLights(false, 1);
Rhamao 6:91e478ee227e 84 rst();
Rhamao 6:91e478ee227e 85 setLights(false, 5);
Rhamao 6:91e478ee227e 86 setLights(true, 2);
Rhamao 6:91e478ee227e 87 setLights(true, 4);
Rhamao 6:91e478ee227e 88 wait(100.0);
Rhamao 6:91e478ee227e 89 //}
Rhamao 6:91e478ee227e 90 }
bcostm 0:b045ca817e2c 91
bcostm 0:b045ca817e2c 92