0

I am trying to add a variable 'ch' for a radio function in microbit, but always I compile I receive an error message.

The idea is send any argument to ch to be incorporate in the radio config function.

from microbit import *
import radio
radio.on()
#-----------
# This channel can vary due to an external input
ch = 30
radio.config(channel=ch) # the original syntaxes is: radio.config(channel=7)

#-------------------

Appreciate if someone can help.

user3483203
  • 50,081
  • 9
  • 65
  • 94
  • 1
    Can you post the error message? – user3483203 Apr 20 '18 at 00:09
  • TypeError: not all arguments converted during string formatting – Edson Sobreira Apr 20 '18 at 00:33
  • I don't think the error is coming from the code you posted, can you post the line that is throwing the error? – user3483203 Apr 20 '18 at 00:35
  • Why do you use `%ch` – user3483203 Apr 20 '18 at 01:03
  • import radio from microbit import * radio.on() while True: if button_a.was_pressed(): ch = 19 if button_b.was_pressed(): ch = 20 radio.config(channel=%ch) incoming = radio.receive() if incoming == 'teste': display.scroll("Channel"%ch) – Edson Sobreira Apr 20 '18 at 01:04
  • Sorry it´s my first time here I can´t put in a code format. I have used %ch, just for try. I have also let as ch, only, but no success as well. In other languages, like vba, vb I know that is possible to combines variable into functions but I have not idea about Python. The problem I see is that the microbit argument is "radio.config(channel =7" - so I can´t find a way to break the function, removing the 7 and put a variable and the function still be valid – Edson Sobreira Apr 20 '18 at 01:05
  • By the way, thanks... – Edson Sobreira Apr 20 '18 at 01:10
  • I could make it doing this: radio.config(channel=(ch)) Thanks – Edson Sobreira Apr 20 '18 at 01:42
  • I think your issue was trying to use `radio.config(channel=%ch)` – user3483203 Apr 20 '18 at 01:42

1 Answers1

1

Your error isn't coming from the radio.config(channel=ch) line it's display.scroll("channel" % ch) should read display.scroll("channel %d" % ch)

phil
  • 561
  • 3
  • 10