Search the Community
Showing results for tags 'turn'.
Found 3 results
Andman posted a topic in LEGO Technic and Model TeamI'm missing a place where Powered Up code can be gathered and explained so other guys can reuse it or find inspiration. I had a discussion with @Jim how that could work out in this forum. I was thinking about having something like the hall of fame for code which underwent optimizations in a dedicated thread and which was proven to work. But this might lead to several thread which are prone to be inactive. So we decided to start with a single thread to publish PU code and discuss it. If it gets to chaotic We could have two separate thread. One for discussion and help request and the other one for working and optimized code. To keep things orderly, a general structure might be helpful. So here we start with my proposal. TL;DR: Automatic brake lights based on speed reduction Description: The following code switches brakes lights on in case the speed is reduced. That works for reducing speed while driving forward and backward. When the speed reaches 0, the light are turned off. In this code I'm using PF lights controlled by the Boost color and distance sensor. But that can be replaced with PU lights. Code: Video Declaration of variables: a - Used to control the speed, is set by the slider 0 b - Speed (a) at the first point in time c - Speed (a) at the second point in time d - Speed difference between b and c Detailed walkthrough: The code block consists of three rows. The first row consists of a loop (left) and the code block to control the speed of the motor (right). Most of the code blocks in the loop are not needed. You actually just need the first block which sets constantly a value for the variable a to control the speed. The rest are widgets for testing timings. The second row is the logic to detect speed differences. To do that constantly, a loop is used again. It simply reads a, the speed at different times. You can adjust the time between the measurments according to your needs. In my case 0,08s worked well. At the end of the loop the difference is set to the variable d. The value can be something between 100 and -100. The third loop at the bottom contains the logic to turn the brake lights on or off. You will also notice the purple blocks. They are used to control the PF lights. I'll come to that in a bit. First i want to explain the logic to turn the lights off an on. There are three scenarios: Driving forwards Driving backwards Parking When you are driving forward the max value of a is 100. Lets say the speed is suddenly reduced to 50. The difference is 50. When you are driving backwards the max value for a is -100. The speed is again reduced by 50. The difference is -50. When you are parking the difference is of course 0, because it doesn't change. So i have two condition i want to check for: Am I driving backwards or forwards? Is there a speed difference? I can exclude the third check, parking, by checking values for a that are greater or smaller than 0. So, in one sentence: IF there is a speed difference AND the speed is GREATER THAN 0 OR IF there is a speed difference AND the speed is SMALLER THAN 0 then turn on the light (upper purple block at the end). But how to control PF lights with Powered UP??? That is covered for example by @kbalage here. The first purple code block on the left sets the port and the correct mode for the boost sensor. The two purple code blocks on the right side control the brightness of the PF lights. D is the port where the sensor is connected to, 3 is the channel 4 on the PF IR receiver, 5 is the red or blue port on the IR receiver, 7 switches the light to max brightness, 8 turns it off.
Murdoch17 posted a topic in LEGO Train TechI was inspired by a failed Ideas project railroad round house and shed from this builder to make this Wild West armstrong turn table in LDD. I'm thinking of doing this model instead of the the two track shed, as it is a bit smaller than the twice-as-tall shed. As this a mechanical table powered by brute force and not steam, electric, or pneumatic means, the table has four angled "iron" bars for mini-figures to grip to pretend-turn the table manually. (This type of table is called an armstrong turn table.) The two sets of tiles on the middle of the table should have this GREAT and this WEST prints from the Toy Story 3 line. NOTE: The flex tracks are supposed to be taken apart into two halves for them to fit on the table ends. You should only need one flex track instead of two as shown, as one whole equals two half units. The 3 and 1/2 track long table has eight tracks radiating outwards on it, with the possibility of more or less tracks if needed being an option in the future. If this was built in real life, the four main locomotives will enter on the bottom-most track and proceed to be rotated to the correct stub-end track for storage. However, the BTTF Time Train cannot fit on the rotating table, (it's just a bit too long) so it will sit on the straight-through track and just run across the table to get off at the other side. (All the items but the blue steam engine and table itself have been bought and built in real life.) As usual, comments, questions, suggestions, and complaints are always welcome!