microbit why blinking leds is so slow? - pause

Using this basic example code from microbit, blinking heart, I tried to change the delay of blinking with the pause argument. However, the minimum actual blinking frequency is around 500ms, no matter what value i put.
Do you know why, and how I can achieve much faster blinking with led patterns (like show_icon or show_leds function).
def on_forever():
basic.show_icon(IconNames.HEART)
basic.pause(50)
basic.show_icon(IconNames.SMALL_HEART)
basic.pause(50)
basic.forever(on_forever)
Thanks.

You have tagged this as micropython but I don't believe that is what you are using. I think you are running with the Python in the MakeCode editor.
Looking at the help page for for the MakeCode show_icon, it says it is called with:
def basic.show_icon(icon: IconNames, interval: null): None
with the following details about interval:
interval (optional), the time to display in milliseconds. default is
600.
As you were not putting a value for interval it was defaulting to 600 milliseconds which meant your code was putting 650 milliseconds delay between each icon.
I was able to vary the duration an icon was displayed with the following:
def on_forever():
basic.show_icon(IconNames.HEART, 100)
basic.show_icon(IconNames.SMALL_HEART, 400)
basic.show_icon(IconNames.HEART, 100)
basic.show_icon(IconNames.SMALL_HEART, 800)
basic.forever(on_forever)

Related

How to reset time for data logging in micro:bit micropython

I would like to start data logging in a bbc micro:bit with the press of its button_a, in order to be able to synchronize the timestamps with an external clock.
The idea is that, if I press the button at 12:10 o'clock, I would know that the first row of data (with 0.00 timestamp) was taken at that time (+/- human reaction time, of course).
The problem is that the zero time of the timestamps begin when the bbc micro:bit is turn on (or reset); so the first timestamp in the log file is not 0.00.
Of course, I could synchronize with that turning-on, but I think it would not be that accurate (I'm using the micro:bit with a robotbit board, which has a big 'on-off' switch.)
What I would like would be some kind of reset_time() method. :)
The code is this:
from microbit import *
import log
log.set_labels('altitude', 'azimuth', 'measure', timestamp=log.SECONDS)
# Wait until Button 'A' is pressed. This way, we can sinchronize the measures with an external clock or watch
while not button_a.was_pressed():
pass
for altitude in...
for azimuth in...
measure=take_reading()
log.add({
'altitude': altitude,
'azimuth': azimuth,
'measure': measure
})
The full code is here: https://github.com/lopezsolerluis/foto-teodolito-log

Donchian Channel Stop Loss

In Pine Script I'm coding a Donchian Channel trading system, where you go long on a 20-day high, and go short on a 20-day low.
I'm fine with coding the opening and closing of the positions, but I'm struggling with coding the initial Stop-Loss level, which I need to remain *fixed *while the whole position is open.
E.g. When you go long on the break of a 20-day high, I would like the initial stop loss to remain fixed at the 20-day low at the time of entry - and for this stop loss to not change.
I can code other versions of stop losses - like "strategy.position_average_price - atr(4)" but how would I link the stop loss to be fixed at the 20-day low at the point of entry?
Many, many thanks,
David.
DonchianLow=ta.lowest(close[1],20)
strategy.exit("Exit Long", from_entry="Long", stop=strategy.average_position_price - DonchianLow)
You must set your strategy.exit only once.
You can use a piece of code like this :
if strategy.position_size == 0 // no open order
if my_entry_condition
strategy.entry('long', strategy.long, qty=Q_Jetons, limit=limiteachat)
strategy.exit(id='Exit', from_entry="long", stop=StopLoss)
This way your strategy.exit is call one time only, and your SL won't change.

Mouse move on element in protractor

I want to hover over a element and later click on it.
Below is the code
await browser.actions().mouseMove(elm, { x: 200, y: 200 }).perform();
await browser.wait(EC.visibilityOF(elm2),10000);
await elm2.click();
I also tried without the offset, like for instance:
await browser.actions().mouseMove(elm).click().perform();
However , I could not get the hover effect and click on the element I wanted , i.e elm2 in this case.
My protractor version is 5.4.1
Appreciate your assistance.
Thanks
I have found the routines in protractor-test-helper extremely useful and robust. These (and instructions for use and installation) can be found at github.com/hetznercloud/protractor-test-helper
So in your case you would say something like:
import { click, hover} from '#hetznercloud/protractor-test-helper/dist';
and later
await hover(elm, 10000); //hover over item, waiting up to 10 seconds
await click(elm2, 10000, 3); //waits for elm2 to show up, up to 10 seconds, clicks on it, 3 retries
But if you just want to look at their hover implementation code for inspiration (not all that different from yours without the offset and with the structure of the three beginning lines), it is at line 55 of https://github.com/hetznercloud/protractor-test-helper/blob/master/dist/actions.js
I know this doesn't tell you exactly how to change what you have, but I hope it gives you at least one (or two) ways to move forward.

Cryengine 5.4 commands

I wanted to cap FPS in cryengine. I was advised to use commands r_Vsync 0 and sys_maxfps 30 (I could make a mistake, but in console I used the correct ones), but FPS is still over 360. How can I fix this?
To limit the framerate in the exported game (GameLauncher), you have to enter these two commands in order
r_VSync = 0
sys_MaxFps = 60 (if you want to cap it to 60 fps)
Unfortunately is not possible to limit your fps in the editor because of a design choice. If you really want to limit them, you could check this out, though you would have to recompile the engine.
Here you can also find a complete list of all the console commands with their possible values and effects.
I hope I helped you :)

Editing Timeline from CCB file in cocos

I did some research into this and couldn't really find anything, so if this is a repetitive question I apologize. but anyway I have made a CCB file in CocosBuilder and I would like to start the timeline, for example, at one second instead of playing from the beginning. Is there a way to do this? Thanks for the help guys.
Edit: i would like this to be done in the code.
I am using 2.2.1 Cocos2DX version. I think there is no option to play it from given interval. But you can tweak yourself to get it done. (Not simple one)
You have to go to CCBAnimationManager and there you get "mNodeSequences".
It is dictionary and you get difference properties there like "rotation position etc..."
values there.
Internally AnimationManager reads this value (These values are specified in your CCB)
and puts in runAction queue.
So you have to break it as you want.(Ex. 5 min timeline you have. But you want to start
from 1 min then you have run first 1 min Actions without delay and for remaining you
have properly calculate tween intervals.
It's long procedure and needs calculation. If you don't know any other simpler way try this. If you know pls let us know (Post it).