# Scroll:bit coding help wanted

**URL:** <https://forums.pimoroni.com/t/scroll-bit-coding-help-wanted/9310>\
**Category:** Support\
**Created:** [December 7, 2018, 3:17pm UTC](https://forums.pimoroni.com/t/scroll-bit-coding-help-wanted/9310 "2018-12-07T15:17:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_Handy\_Andy](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@The\_Handy\_Andy](https://forums.pimoroni.com/u/The_Handy_Andy)\
**Post date:** [December 7, 2018, 3:17pm UTC](https://forums.pimoroni.com/t/scroll-bit-coding-help-wanted/9310/1 "2018-12-07T15:17:35Z")

</div>

Hi all, I am trying to use a scroll;bit to display different messages depending on which button has been pressed. I want each message to be scrolled multiple times (ideally as a continuous loop). My base code in java to display each message twice is:

input.onButtonPressed(Button.A, function () {  
for (let i = 0; i \< 2; i++) {  
scrollbit.scrollText(“one”, 128, 50)  
}  
})  
input.onButtonPressed(Button.B, function () {  
for (let i = 0; i \< 2; i++) {  
scrollbit.scrollText(“two”, 128, 50)  
}  
})

The " for (let) " line controls the number of time the message is scolled.  
If I change it to " while (true) " when I restart the micro:bit and press one of the buttons I get continuous scrolling but pressing the other button doesn’t change the message I have to reset first!

input.onButtonPressed(Button.A, function () {  
while (true) {  
scrollbit.scrollText(“one”, 128, 50)  
}  
})  
input.onButtonPressed(Button.B, function () {  
while (true) {  
scrollbit.scrollText(“two”, 128, 50)  
}  
})

Its like once the first button has been pressed the micro:bit stops ‘listening’ for any other inputs (i.e. the other button being pressed).

Any help gratefully recieved!  
Andrew

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [December 7, 2018, 3:38pm UTC](https://forums.pimoroni.com/t/scroll-bit-coding-help-wanted/9310/2 "2018-12-07T15:38:09Z")

</div>

Micro Python?

If input.onButtonPressed

elif input.onButtonPressed

Maybe?

I do believe there can be only one While true loop.

I have a Micro-bit, several actually, haven’t done anything with them in a long while. I don’t have the scroll bit though. Might be able to play around with the button part of the code though, latter on today.  
Three ``` before and after your posted code will put it in code tags.  
It’s the symbol on the ~ key, under the ~.

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [December 8, 2018, 11:11am UTC](https://forums.pimoroni.com/t/scroll-bit-coding-help-wanted/9310/3 "2018-12-08T11:11:41Z")

</div>

This is a python file I did up for my Micro-Bit that uses the A & B buttons. I hope it helps.

```auto
# Add your Python code here. E.g.

from microbit import *
import microbit
import music

cake = Image("09090:"
             "07070:"
             "55555:"
             "50005:"
             "55555")

while True:

    if microbit.button_a.is_pressed():
        display.show(cake)
        music.play(music.BIRTHDAY,pin=microbit.pin0, wait=True, loop=False)
        #sleep(9000)
    elif microbit.button_b.is_pressed():
        display.scroll("60")
        display.show(Image.SAD)
        music.play(music.WAWAWAWAA,pin=microbit.pin0, wait=True, loop=False)
    else:
        display.show(Image.HAPPY)

```
