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.
Revision 1:dc7c5869f9e1, committed 2019-04-02
- Comitter:
- corsa1600
- Date:
- Tue Apr 02 18:07:35 2019 +0000
- Parent:
- 0:f0345f20337e
- Commit message:
- LED_Blink
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Apr 02 17:24:04 2019 +0000
+++ b/main.cpp Tue Apr 02 18:07:35 2019 +0000
@@ -8,12 +8,14 @@
DigitalOut green(p24);
DigitalOut blue(p25);
-class StopLight {
+class StopLight
+{
private:
+ Timer t1; //mein Timer
EventQueue _queue;
int _pending;
- enum state { RED, GREEN, YELLOW };
+ enum state { RED, GREEN, YELLOW,GREENBLINK };
// The _step function is a traditional FSM which enqueues transitions onto the event queue
void _step(state transition) {
@@ -25,7 +27,12 @@
case GREEN:
set_green();
- _pending = _queue.call_in(1000, this, &StopLight::_step, YELLOW);
+ _pending = _queue.call_in(1000, this, &StopLight::_step, GREENBLINK);
+ break;
+
+ case GREENBLINK:
+ set_greenBlink();
+ _pending = _queue.call_in(3000, this, &StopLight::_step, YELLOW);
break;
case YELLOW:
@@ -34,18 +41,56 @@
break;
}
}
- void set_red(){
+
+void set_red()
+ {
red = 0; green = 1; blue = 1;
}
- void set_green(){
+void set_green()
+ {
red = 1; green = 0; blue = 1;
+
}
- void set_yellow() {
+void set_greenBlink()
+ {
+ t1.start(); // ich starte meinen Timer
+ //red = 1; green = 1; blue = 1;
+ if(t1.read_ms()>200) // erst wenn 10Hz
+ {
+
+ if(green=1)
+ {
+ red = 1; green = 1; blue = 1;
+ }
+ else
+ {
+ red = 1; green = 0; blue = 1;
+ }
+ t1.reset(); // ich resete meinen Timer
+ }
+
+ if ( green=0)
+ green=1;
+ else
+ green=0;
+ }
+void set_yellow()
+ {
red = 0; green = 0; blue = 1;
+
+ /*
+ wait_ms(150);
+ red = 1; green = 1; blue = 1;
+ wait_ms(150);
+ red = 0; green = 0; blue = 1;
+ wait_ms(150);
+ red = 1; green = 1; blue = 1;
+ */
}
public:
// The fire function can immediately change states in the FSM
- void fire() {
+ void fire()
+ {
_queue.cancel(_pending);
_queue.call(this, &StopLight::_step, GREEN);
_queue.dispatch();
@@ -54,7 +99,8 @@
StopLight sl;
-int main (void) {
+int main (void)
+{
sl.fire();
wait(osWaitForever);
}
\ No newline at end of file