Projekt:Calliope/Scripte/3

Aus Un-Hack-Bar
Wechseln zu: Navigation, Suche
let Counter = 0
input.onButtonPressed(Button.B, () => {
   radio.sendValue("changeValue", 2)
   Counter += -1
})
input.onButtonPressed(Button.A, () => {
   radio.sendValue("changeValue", 1)
   Counter += 1
})
radio.onDataPacketReceived( ({ receivedString: name, receivedNumber: value }) =>  {
   if ("currentValue" == name) {
       Counter = value
   }
   if ("changeValue" == name) {
       if (value == 1) {
           Counter += 1
       }
       if (value == 2) {
           Counter += -1
       }
   }
   if ("getValue" == name) {
       radio.sendValue("currentValue", Counter)
   }
})
input.onButtonPressed(Button.AB, () => {
   radio.sendValue("currentValue", Counter)
})
radio.setGroup(17)
radio.sendValue("getValue", 1)
basic.forever(() => {
   basic.showNumber(Counter)
})