![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Potencia
main.cpp@0:413a44475256, 2015-12-03 (annotated)
- Committer:
- SolManB
- Date:
- Thu Dec 03 02:36:22 2015 +0000
- Revision:
- 0:413a44475256
Potencia;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SolManB | 0:413a44475256 | 1 | #include "mbed.h" |
SolManB | 0:413a44475256 | 2 | |
SolManB | 0:413a44475256 | 3 | PwmOut led(LED1); // led 1 indicates dim value |
SolManB | 0:413a44475256 | 4 | DigitalOut led2(LED2); // led 2 indicates delay time for interrupts |
SolManB | 0:413a44475256 | 5 | |
SolManB | 0:413a44475256 | 6 | DigitalOut SSR(p27); |
SolManB | 0:413a44475256 | 7 | Serial pc(p9,p10); |
SolManB | 0:413a44475256 | 8 | Timeout SSRtriggerOn; |
SolManB | 0:413a44475256 | 9 | DigitalOut foco(p16); |
SolManB | 0:413a44475256 | 10 | DigitalOut motor(p17); |
SolManB | 0:413a44475256 | 11 | DigitalOut elec(p20); |
SolManB | 0:413a44475256 | 12 | Ticker cruce; |
SolManB | 0:413a44475256 | 13 | |
SolManB | 0:413a44475256 | 14 | volatile float dim; |
SolManB | 0:413a44475256 | 15 | const float powerlinefrequency=60.000; |
SolManB | 0:413a44475256 | 16 | |
SolManB | 0:413a44475256 | 17 | void triggerOn() |
SolManB | 0:413a44475256 | 18 | { |
SolManB | 0:413a44475256 | 19 | SSR = 1; |
SolManB | 0:413a44475256 | 20 | led2=0; |
SolManB | 0:413a44475256 | 21 | } |
SolManB | 0:413a44475256 | 22 | |
SolManB | 0:413a44475256 | 23 | void dimmer() |
SolManB | 0:413a44475256 | 24 | { |
SolManB | 0:413a44475256 | 25 | // turn off SSR at zero crossing |
SolManB | 0:413a44475256 | 26 | SSR = 0; |
SolManB | 0:413a44475256 | 27 | // compute time delay using dim value and set timer interrupt |
SolManB | 0:413a44475256 | 28 | // triggers SSR after a small post zero crossing time delay |
SolManB | 0:413a44475256 | 29 | SSRtriggerOn.attach(&triggerOn,(dim)/(2*powerlinefrequency)); |
SolManB | 0:413a44475256 | 30 | led2=1; |
SolManB | 0:413a44475256 | 31 | } |
SolManB | 0:413a44475256 | 32 | |
SolManB | 0:413a44475256 | 33 | int main() |
SolManB | 0:413a44475256 | 34 | { |
SolManB | 0:413a44475256 | 35 | cruce.attach(&dimmer, 0.00833333); |
SolManB | 0:413a44475256 | 36 | foco=0; |
SolManB | 0:413a44475256 | 37 | motor=0; |
SolManB | 0:413a44475256 | 38 | elec=0; |
SolManB | 0:413a44475256 | 39 | |
SolManB | 0:413a44475256 | 40 | float m; |
SolManB | 0:413a44475256 | 41 | //set up interrupt routine to detect AC line zero crossings |
SolManB | 0:413a44475256 | 42 | |
SolManB | 0:413a44475256 | 43 | m=180; |
SolManB | 0:413a44475256 | 44 | // main program only sets dimmer level (dim) |
SolManB | 0:413a44475256 | 45 | // interrupt routines dim the light |
SolManB | 0:413a44475256 | 46 | while(1) { |
SolManB | 0:413a44475256 | 47 | char da=pc.getc(); |
SolManB | 0:413a44475256 | 48 | //increase brightness |
SolManB | 0:413a44475256 | 49 | if(da=='y') |
SolManB | 0:413a44475256 | 50 | { |
SolManB | 0:413a44475256 | 51 | if(m<180)m=m+5; |
SolManB | 0:413a44475256 | 52 | } |
SolManB | 0:413a44475256 | 53 | if(da=='x') |
SolManB | 0:413a44475256 | 54 | { |
SolManB | 0:413a44475256 | 55 | if(m>0)m=m-5; |
SolManB | 0:413a44475256 | 56 | } |
SolManB | 0:413a44475256 | 57 | dim=m/180+0.001; |
SolManB | 0:413a44475256 | 58 | if(da=='c')foco=1; |
SolManB | 0:413a44475256 | 59 | if(da=='d')foco=0; |
SolManB | 0:413a44475256 | 60 | if(da=='a')motor=1; |
SolManB | 0:413a44475256 | 61 | if(da=='b')motor=0; |
SolManB | 0:413a44475256 | 62 | if(da=='e')elec=1; |
SolManB | 0:413a44475256 | 63 | if(da=='f')elec=0; |
SolManB | 0:413a44475256 | 64 | printf("\n\rGrados: %f, %c",m,da); |
SolManB | 0:413a44475256 | 65 | |
SolManB | 0:413a44475256 | 66 | } |
SolManB | 0:413a44475256 | 67 | } |