mjstephens Posted December 7, 2022 Posted December 7, 2022 Hello, I'd be grateful for help with Powered Up coding please. I'm using the colour and distance sensor 88007 fitted to the underside of a train. I've tested many different colour tiles using the report function and have settled on a small range of colours that return true readings. Unfortunately I still get false readings from other blank parts of my track, with yellow and blue falsely triggering actions when the tile doesn't exist in that location. I notice that the distance reading does seem reliable so a coloured tile placed on the track shows a 0 distance whereas the sleepers and track bed read 1 and 3/4 respectively. What I'd like to do with the code is have an action triggered only when, for example, the sensor reads a 0 distance AND blue at the same time. The closest I've come to making this work is the ForkJoin flow block but the sensor can read a false colour elsewhere on the track, then detect the correct 0 distance (on a different coloured tile) before it moves to the next block. Ideally the code would only progress once both colour and distance conditions are met simultaneously. If only one condition is met, the code should revert to a state where it looks for a new instance of the condition. I've attached a basic example of my code. Any help would be greatly appreciated Quote
Ts__ Posted December 7, 2022 Posted December 7, 2022 (edited) first and fast idea (without test or APP): In a loop: - read sensor by distance and store in a variable - read sensor by color and store in variable - then you can check both variables with AND on your condition and let execute an action e.g. over a flag. Thomas Edited December 7, 2022 by Ts__ Quote
mjstephens Posted December 7, 2022 Author Posted December 7, 2022 Thanks so much, your idea worked perfectly and I have a far better understanding of the app now. I've attached a screenshot of it's of help to anyone else. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.