Black Lives Matter - Action and Equality.
0

make code microbit and crickit signals
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

make code microbit and crickit signals

by nickine9 on Mon May 11, 2020 6:04 am

I am trying to use 6 signal connectors linked to tilt switches for a nerf shooting game. I prototyped one target and got in working so i wired up the other five and its doesn't work as expected.

if all switches are on the program works and lights a led on a neopixel ring for each contact but if one switch is off it seems the other are ignored.

I am using restistors for the switches

I saw a note at the top of the signals page of your cricket guide that they can sometimes lock using a circuit playground but that they can be used with a microbit.

it is more than likely i have done something silly with my wiring, which is a bit spaghetti like, but before i do another teardown and rebuild I thought i would check if anyone else has experienced similar problems and found a workaround.

thanks in advance for any help and may i say how totally impressed I am by your covid related efforts.

nickine9
 
Posts: 133
Joined: Fri Jan 06, 2017 4:14 am

Re: make code microbit and crickit signals

by johnpark on Fri May 15, 2020 3:46 pm

Sounds fun! Please upload clear photos of your wiring setup and code so we can try to help troubleshoot.

johnpark
 
Posts: 746
Joined: Wed Mar 25, 2009 2:15 pm

Re: make code microbit and crickit signals

by nickine9 on Sat May 16, 2020 7:30 am

Hi John,

Thanks for the reply. I have done my best to provide a clear photo but lighting conditions in my work room are not great.

IMG_1024.jpeg
IMG_1024.jpeg (97.17 KiB) Viewed 75 times


the javascript code from make code is
Code: Select all | TOGGLE FULL SIZE
let strip = neopixel.create(DigitalPin.P16, 7, NeoPixelMode.RGB)
basic.forever(function () {
    if (crickit.signal1.digitalRead()) {
        strip.setPixelColor(2, neopixel.colors(NeoPixelColors.Red))
        strip.show()
        basic.pause(1000)
    }
    if (crickit.signal2.digitalRead()) {
        strip.setPixelColor(1, neopixel.colors(NeoPixelColors.Blue))
        strip.show()
        basic.pause(1000)
    }
    strip.clear()
    strip.show()
    basic.pause(500)
    strip.showColor(neopixel.colors(NeoPixelColors.Green))
    basic.pause(1000)
})


The symptoms are

if both switches are on two leds light up on the neopixel ring, but if only one switch is on neither Led lights up. I get the same symptoms if i connect more switches (and change the code appropriately). I have also tried with analogue reads (different code) and got the same symptoms.

stay safe

nick

nickine9
 
Posts: 133
Joined: Fri Jan 06, 2017 4:14 am

Re: make code microbit and crickit signals

by johnpark on Mon May 18, 2020 4:28 pm

I'm wondering if you want the logic to look more like this:
Code: Select all | TOGGLE FULL SIZE
let strip = neopixel.create(DigitalPin.P16, 7, NeoPixelMode.RGB)
basic.forever(function () {
    if (crickit.signal1.digitalRead()) {
        strip.setPixelColor(2, neopixel.colors(NeoPixelColors.Red))
        strip.show()
        basic.pause(1000)
    } else if (crickit.signal2.digitalRead()) {
        strip.setPixelColor(1, neopixel.colors(NeoPixelColors.Blue))
        strip.show()
        basic.pause(1000)
    } else {
        strip.clear()
        strip.show()
        basic.pause(500)
        strip.showColor(neopixel.colors(NeoPixelColors.Green))
        basic.pause(1000)
    }
})

johnpark
 
Posts: 746
Joined: Wed Mar 25, 2009 2:15 pm

Re: make code microbit and crickit signals

by nickine9 on Tue May 19, 2020 3:47 am

Hi John

thanks for the reply. I test each button with a separate if statement (without the else if) because in some scenarios I need to check all the buttons in one pass. In terms of this project I have a similar version of my code running on a CPX but would really like to run it on the microbit/crickit combo as I want to use servos to move the targets but only if i can make the signals work.

nick

nickine9
 
Posts: 133
Joined: Fri Jan 06, 2017 4:14 am

Please be positive and constructive with your questions and comments.