Search found 193 matches

by karfas
Sat Jul 23, 2022 5:20 pm
Forum: General Discussion and Questions
Topic: Traffic lights with a button interrupt - how would you have done it?
Replies: 12
Views: 10151

Re: Traffic lights with a button interrupt - how would you have done it?

@pythoncoder: You misunderstood me, I think. Even when this came out as an anti-asyncio rant, I also wrote asyncio is great for doing many different things in parallel, and it's definitely worth learning. Handling 300 traffic lights in a small city ? Asyncio, of course. Nothing better exists in the ...
by karfas
Sat Jul 23, 2022 6:56 am
Forum: ESP32 boards
Topic: int() Anomaly
Replies: 19
Views: 9699

Re: int() Anomaly

Limited precision for float values.
For your last example, the int gets converted to a float, the subtraction returns a float, you convert it to int.
by karfas
Fri Jul 22, 2022 4:24 pm
Forum: Programs, Libraries and Tools
Topic: urequest could not request the server after short downtime
Replies: 2
Views: 1949

Re: urequest could not request the server after short downtime

Shouldn't settimeout() get called before connect() ? I wonder that connect() doesn't raise an exception when the connect (obviously) is not working. See e.g. https://github.com/micropython/micropython-lib/blob/master/python-ecosys/urequests/urequests.py: s = usocket.socket(ai[0], usocket.SOCK_STREAM...
by karfas
Fri Jul 22, 2022 3:55 pm
Forum: General Discussion and Questions
Topic: Traffic lights with a button interrupt - how would you have done it?
Replies: 12
Views: 10151

Re: Traffic lights with a button interrupt - how would you have done it?

the best way to do this kind of thing is with asynchronous programming: asyncio I stronly disagree , at least for this application. asyncio is great for doing many different things in parallel, and it's definitely worth learning. The traffic lights for a real-world crossroad don't require a gazilli...
by karfas
Fri Jul 22, 2022 11:17 am
Forum: ESP8266 boards
Topic: ESP-01s - Issue after deepsleep
Replies: 2
Views: 17709

Re: ESP-01s - Issue after deepsleep

Where in your code your WLAN and WebREPL starts ?

I have no experience with the 8266, but for an ESP32 the deactivation of any WIFI functions (e.g. wlan.active(False)) is a requirement für deep sleep.
by karfas
Fri Jul 22, 2022 7:56 am
Forum: General Discussion and Questions
Topic: Traffic lights with a button interrupt - how would you have done it?
Replies: 12
Views: 10151

Re: Traffic lights with a button interrupt - how would you have done it?

Is that both red and green off? Traffic lights don't behave like that. Well, my traffic light can be switched off :D. Thanks for the great example of complex logic for a (perceived) simple problem. My program above is too short to show all cases you showed in your first post (and I'm too lazy to de...
by karfas
Fri Jul 22, 2022 6:42 am
Forum: Raspberry Pi microcontroller boards
Topic: PicoW NTP Client with Temp sensor and serLCD via I2C
Replies: 7
Views: 14705

Re: PicoW NTP Client with Temp sensor and serLCD via I2C

Out of curiosity: Why do you need the DST change times of the last or future N years on a microcontroller? In the far distant past, the TZ environment in Unix/POSIX "MEZ-1MES,M3.5.0,M10.5.0" (search Google for "TZ environment") had all relevant information to switch between UTC and local time for cu...
by karfas
Thu Jul 21, 2022 9:32 pm
Forum: General Discussion and Questions
Topic: Traffic lights with a button interrupt - how would you have done it?
Replies: 12
Views: 10151

Re: Traffic lights with a button interrupt - how would you have done it?

A simple FSM approach, using only green+red. In a real program, I would most likely create a definition of all state changes and transitions using a dictionary. # simple FSM. should be RED for 1 second, GREEN for 1/2 second. # setting event to EVT_STOP turns everything off and ends the loop. from ti...
by karfas
Thu Jul 21, 2022 4:43 pm
Forum: General Discussion and Questions
Topic: Traffic lights with a button interrupt - how would you have done it?
Replies: 12
Views: 10151

Re: Traffic lights with a button interrupt - how would you have done it?

I don't think there is an easy way to stop sleep(). However, you could create your own stoppable sleep function: stop_mysleep = 0 def mysleep(seconds) global stop_mysleep stop_mysleep = 0 for _ in range(seconds*10) if stop_mysleep: return sleep(0.1) Then, set stop_mysleep in the interrupt function. ...
by karfas
Wed Jul 20, 2022 8:23 pm
Forum: ESP32 boards
Topic: in Driver Writing getting char pointer
Replies: 1
Views: 1333

Re: in Driver Writing getting char pointer

There is no such thing like a char * in (micro)python. The address of something is usually a plain int.

You might want to acces a bytes or string object.
Check out any functios (e.g. in ports/*/*.c) which get a string or bytes object.