State Machine: Unterschied zwischen den Versionen
Stella (Diskussion | Beiträge) |
Br (Diskussion | Beiträge) |
||
Zeile 88: | Zeile 88: | ||
CONTROL_END | CONTROL_END | ||
</pre> | </pre> | ||
− | It is a state | + | It is a state machine to control a pulse relais with two coils for a |
− | + | coffeemachine. If you press the green button the machine is switched | |
on and the green LED light up. At the same time the server gets the | on and the green LED light up. At the same time the server gets the | ||
message "On". If you press the red button it sends a message "Cleaning" | message "On". If you press the red button it sends a message "Cleaning" | ||
Zeile 96: | Zeile 96: | ||
The server can control the circuit by sending a message like this: | The server can control the circuit by sending a message like this: | ||
<pre> | <pre> | ||
− | echo "c6 set state 1" | netcat -q1 | + | echo "c6 set state 1" | netcat -q1 coffeemachine 2701 |
</pre> | </pre> | ||
To check the status it should send something like: | To check the status it should send something like: | ||
<pre> | <pre> | ||
− | echo "c6 get state" | netcat -q1 | + | echo "c6 get state" | netcat -q1 coffeemachine 2701 |
</pre> | </pre> | ||
− | Is the answer e.g. "state 100" the | + | Is the answer e.g. "state 100" the machine is off. |
The job is done without timers because there was no space left in the device. | The job is done without timers because there was no space left in the device. | ||
With TCP, control6, named pins and rfm12 it nearly takes 16K. | With TCP, control6, named pins and rfm12 it nearly takes 16K. | ||
[[Category:Control6 Examples]] | [[Category:Control6 Examples]] |
Version vom 6. Juni 2010, 15:08 Uhr
CONTROL_START ECMD_GLOBAL(state,255); ECMD_GLOBAL(c,0); PIN_INPUT(Key_green) PIN_INPUT(Key_red) PIN_OUTPUT(LED_green) PIN_OUTPUT(LED_red) PIN_OUTPUT(Pulserelais_on) PIN_OUTPUT(Pulserelais_off) THREAD(states) ON state==0 DO PIN_SET(LED_red); PIN_CLEAR(LED_green); PIN_SET(Pulserelais_off); ESEND(192.168.28.1, "Off\"); state=10; c=0; END ON state==10 DO c=c+1; ON c==20 DO c=0; PIN_CLEAR(Pulserelais_on); PIN_CLEAR(Pulserelais_off); state=100; END END ON state==1 DO PIN_SET(LED_green); PIN_CLEAR(LED_red); PIN_SET(Pulserelais_on); ESEND(192.168.28.1, "On\"); state=11; c=0; END ON state==11 DO c=c+1; ON c==20 DO c=0; PIN_CLEAR(Pulserelais_on); PIN_CLEAR(Pulserelais_off); state=101; END END ON state==2 DO PIN_CLEAR(LED_red); PIN_CLEAR(LED_green); ESEND(192.168.28.1, "Cleaning\"); state=20; END ON state==20 DO c=c+1; ON c==15 DO PIN_SET(LED_green); END ON c==30 DO PIN_CLEAR(LED_green); c=0; END END THREAD_END(states) ON PIN_FALLING(Key_green) DO state=1; END ON PIN_FALLING(Key_red) DO ON state==101 DO state=2; END ON state==20 DO state=0; END END ON STARTUP DO ESEND(192.168.28.1, "Start\"); state=0; THREAD_RESTART(states); END CONTROL_END
It is a state machine to control a pulse relais with two coils for a coffeemachine. If you press the green button the machine is switched on and the green LED light up. At the same time the server gets the message "On". If you press the red button it sends a message "Cleaning" to the server and starts to flash the green LED. If you press it again it sends "Off" and switches the relais off. Then the red LED lights up. The server can control the circuit by sending a message like this:
echo "c6 set state 1" | netcat -q1 coffeemachine 2701
To check the status it should send something like:
echo "c6 get state" | netcat -q1 coffeemachine 2701
Is the answer e.g. "state 100" the machine is off. The job is done without timers because there was no space left in the device. With TCP, control6, named pins and rfm12 it nearly takes 16K.