Please help with the diagram

TIR v4.xodball (14.8 KB)
Good afternoon. I am from Russia and I apologize for my English. I write on the forum through a translator. I have attached a scheme that for some reason does not work for me. I need to turn on the LEDs randomly. And turn off the button. I made the flip-flop block control from the buttons from the beginning. everything worked for me. I changed the inclusion from RANDOM and my project doesn’t work for some reason. Tell me where my error is.

For starters, you only check random output for less-than. If random returns 0.7, you will turn on all 4 LEDs. If random returns 0.8 or higher, you don’t turn on any LEDs.

Also remember that flip-flop will only change when input boolean changes from false to true. If random outputs 0.5, you will turn on the 1st two LEDs. If you press buttons to clear both and random changes to anything less than 0.6, nothing will happen. Output of “less” nodes will either stay in current state or turn off, neither of which will trigger flip-flop.

We need more description of what you are trying to do to determine what else might be wrong. What does “doesn’t work” mean? What are you expecting it to do? What does it actually do?

gweimer. Thank you for your help. Here is a full description of what my nephew and I want to do. 4 photoresistors are connected to the Arduino Board to the analog inputs (A0-A3). To digital outputs (D 8-D11)4 servos are connected. Input D5 recharge (reset result button) .Input D6 “FIRE” button. The display is connected via the i2c bus ( analog output A4; A5). The display shows the remaining cartridge and the number of hits. Now I describe how it should work . The random generator randomly sets numbers 1-4 that enable the servos via the flip flop module. Which rise from the 0-degree position to the 90-degree position. I attached a photo resistor to the servo levers. The laser beam from the gun illuminates the target(the photoresistor is illuminated) we count +1 hit and -1 cartridge ( this is what we drive on the screen ) and return the state of the servo to 0 degrees. Then the cycle repeats .

Sounds like you need to start with the 2nd example in this post: I can't understand how the RANDOM block works, but run gate output to SET instead of TGL on flip-flops. This would allow the same target to pop up twice in a row.

If you only want one target to show at a time, then you should replace clock signal to random node with pulse from code telling you there has been a hit (so next target raises after previous target has been hit).

The output of flip-flops should feed if-else to determine servo position. False should be lowered position; True should be raised position. Actual values will depend on servo orientation, but will likely be 0 & 0.5, or 0.5 and 1 (or reversed if servo is flipped the other direction).

The reset button should RST all flip-flops as well as count of hits & cartridges. Since a hit will also RST flip-flops, you will need an “any” node to allow either pulse to reset each flip-flop.

To count cartridges remaining, it is difficult with existing XOD nodes to do a count-down from a specific number, but you can “fake” it using count up & subtract from max number. For example, assuming a 6-shooter:
Output of subtract is the number of cartridges left.

For the photo-resistors detecting hits, you will need a voltage divider circuit. The analog pin will connect to photo-resistor and a 2nd fixed resistor. The 2 resistors will connect to V+ and GND. Assuming the photo-resistor connects to V+, the reading on the analog pin will increase as light on the detector increases. You will need to do some testing to determine how high the value gets for a hit and how low it goes for ambient light. Somewhere between those values (probably closer to the hit value) is what you want to compare with to determine if there is a hit:
The output for “greater” will go true when there is a hit. If only one target is up at a time, you can use “or” to join all 4 detector “greater” outputs into one hit signal. That pulse should 1) increase counter for hits, 2) reset flip-flops, 3) pulse random to raise the next target. Cartridge count is decremented every time the gun is fired; it doesn’t matter if there is a hit or not.

Note that you probably want a gate node between hit detection and random so it can be disabled when cartridge count reaches zero. You will also want to disable the gun firing so they can’t hit last target after cartridges are gone.

This assumes detectors are hidden when targets are down, so there is no need for extra code to only count hits on targets that are up…it will be impossible to detect a hit when target is down. This also assumes light is emitted from gun only when it is fired; if gun is always shining light, then you need to detect hits only when “FIRE” pin is activated.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.