Iulian Radu
/
AC_dimmer
AC dimmer
Diff: main.cpp
- Revision:
- 1:513c1ae9298f
- Parent:
- 0:e77768001bf6
--- a/main.cpp Sat Dec 13 11:51:17 2014 +0000 +++ b/main.cpp Sat Jan 10 21:04:29 2015 +0000 @@ -10,6 +10,9 @@ }; //defines +#define TRIAC_PIN PTD5 +#define zero_CROSS_PIN PTA13 + #define ERROR_CMD(x) x = x | 0xC0 #define ERROR_MSG(x) x = x | 0xC000 #define MSG_DEFAULT 0x8000 | MIN_DIMM_VALUE @@ -17,7 +20,7 @@ #define MAX_PERIOD 9600 // us // teoretic 10ms #define TRIAC_ON_TIME 25 //us // latimea pulsului pentru activarea triacului. #define DIMM_RX_BUFFER 6 -#define CONNECTION 3 // 1-PC // 2 - BT // 3 - PC + BT +#define CONNECTION 2 // 1-PC // 2 - BT char STEPS = 255; signed char AUTO_DIMM_STEP = 1; @@ -26,8 +29,8 @@ char MAX_DIMM_VALUE = STEPS; PwmOut LED(LED_GREEN); // on board LED -DigitalOut triacOut(PTD5); //output to Opto Triac -InterruptIn zerroCross(PTA13); // only port A or D +DigitalOut triacOut(TRIAC_PIN); //output to Opto Triac +InterruptIn zeroCross(zero_CROSS_PIN); // only port A or D TSIAnalogSlider tsi(9, 10, 39); // board slider Serial pc(USBTX, USBRX); Serial bt(PTA2,PTA1); @@ -82,29 +85,13 @@ else bt.printf("%u",ERROR_MSG(msg.body)); break; - case 3: - if(!err){ - pc.printf("%s# MSG: %u CMD: %u DATA: %u\n",s,msg.body, msg.cmd, msg.data); - bt.printf("%u",msg.body); - }else{ - pc.printf("%s# CMD: %u DATA %u \n",s, ERROR_CMD(msg.cmd), msg.data); - bt.printf("%u",ERROR_MSG(msg.body)); - } - break; } } - - -void ISR_zerroCross(void){ +void ISR_zeroCross(void){ timer.attach_us(&setTriacOn,(MAX_PERIOD/STEPS) * (STEPS - dimmingLevel)); } -void ISR_Serial(void){ - bt.gets(buffer, DIMM_RX_BUFFER); - LED = !LED; -} - void readData(void) { if(bt.readable()) { @@ -182,17 +169,16 @@ int main() { - zerroCross.enable_irq(); //enable routine - zerroCross.fall(&ISR_zerroCross); // falling edge interrupt routine - + zeroCross.enable_irq(); //enable routine + zeroCross.fall(&ISR_zeroCross); // falling edge interrupt routine + bt.baud(9600); //cycling.attach(&testDimming,AUTO_DIMM_PERIOD); - bt.attach(&ISR_Serial); // e mai bine fara intrerupere pentru ca nu apare intreruperea dimmingului LED = 1; // led off. triacOut = 0; // triac off while(true){ //testSlider(); - //readData(); + readData(); } } \ No newline at end of file