timer

python Time a try except

孤街醉人 提交于 2020-12-08 07:58:11
问题 My problem is very simple. I have a try/except code. In the try I have some http requests attempts and in the except I have several ways to deal with the exceptions I'm getting. Now I want to add a time parameter to my code. Which means the try will only last for 'n' seconds. otherwise catch it with except. In free language it would appear as: try for n seconds: doSomthing() except (after n seconds): handleException() this is mid-code. Not a function. and I have to catch the timeout and

Proper implementation of Timer1 for PWM generation

我的梦境 提交于 2020-12-06 12:22:35
问题 On the Atmel ATmega328P (datasheet), there are three timers available for PWM generation (timer0, timer1, and timer2). I already have what I need using the 8-bit timer2, I am just concerned with using different timer instad of timer2, because timer2 is used in various libraries, and I'd like to have more granularity. Thus I'd like to use the 16-bit timer1. Here is what I am using to generate a 25 kHz, variable duty cycle using timer2. For this example, lets consider a 35% duty cycle: void

Python cancel raw_input/input via writing to stdin?

元气小坏坏 提交于 2020-12-05 12:28:05
问题 For starters, I'm on python 2.7.5 and Windows x64, my app is targeted at those parameters. I'm in need of a way to cancel a raw_input after a certain amount of time has passed. Currently I have my main thread starting two child threads, one is the timer (threading.Timer) and the other fires the raw_input. These both return a value to a Queue.queue that the main thread monitors. It then acts on what is sent to the queue. # snip... q = Queue.queue() # spawn user thread user = threading.Thread

Python cancel raw_input/input via writing to stdin?

 ̄綄美尐妖づ 提交于 2020-12-05 12:27:59
问题 For starters, I'm on python 2.7.5 and Windows x64, my app is targeted at those parameters. I'm in need of a way to cancel a raw_input after a certain amount of time has passed. Currently I have my main thread starting two child threads, one is the timer (threading.Timer) and the other fires the raw_input. These both return a value to a Queue.queue that the main thread monitors. It then acts on what is sent to the queue. # snip... q = Queue.queue() # spawn user thread user = threading.Thread

Android scale button on touch

天涯浪子 提交于 2020-11-28 07:47:12
问题 I know how to scale the button to a determinated value, but is there a way to increase/decrease the button size per time as long the user is touching it? Something like this: Button myButton = (Button)findViewById(R.id.myButton); myButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { // Some timer action here or is there a better way? v.setScaleX(v.getScaleX() + 0.1f); v