Operácie

Datalogger cez rádiový prenos: Rozdiel medzi revíziami

Zo stránky SensorWiki

Balogh (diskusia | príspevky)
Bez shrnutí editace
Balogh (diskusia | príspevky)
Bez shrnutí editace
 
(Jedna medziľahlá úprava od rovnakého používateľa nie je zobrazená.)
Riadok 2: Riadok 2:




 
<gallery heights=300px mode="packed">  <!-- slideshow? -->
<gallery heights=200px mode="packed">  <!-- slideshow? -->
Image:microbit-serialRadioNumberTx.png|''Program v blokovom jazyku pre vysielač''
Image:microbit-serialRadioNumberTx.png|''Program v blokovom jazyku pre vysielač''
Image:microbit-serialRadioNumberRx|''a pre prijímač''
Image:microbit-serialRadioNumberRx.png|''a pre prijímač''
</gallery>
</gallery>


Riadok 11: Riadok 10:
<tabs>
<tabs>
<tab name="Javascript"><source lang="javascript">
<tab name="Javascript"><source lang="javascript">
radio.onReceivedNumber(function on_received_number(receivedNumber: number) {
    serial.writeLine("" + ("" + receivedNumber))
})
let AccX = 0
radio.setGroup(1)
basic.forever(function on_forever() {
    radio.sendString("" + ("" + control.millis()) + "," + ("" + AccX))
    led.toggle(2, 2)
    basic.pause(100)
})
    
    
</source></tab>
</source></tab>
<tab name="MS Python"><source lang="python" style="background: LightBlue;">
<tab name="MS Python"><source lang="python" style="background: LightBlue;">
def on_received_number(receivedNumber):
    serial.write_line("" + str((receivedNumber)))
radio.on_received_number(on_received_number)
AccX = 0
radio.set_group(1)
def on_forever():
    global AccX
    AccX = input.acceleration(Dimension.X)
    radio.send_number(AccX)
    basic.pause(100)
basic.forever(on_forever)


</source></tab>
</source></tab>
Riadok 27: Riadok 51:




<gallery heights=200px mode="packed">  <!-- slideshow? -->
<gallery heights=300px mode="packed">  <!-- slideshow? -->
Image:microbit-serialRadioStringTx.png|''Program v blokovom jazyku pre vysielač''
Image:microbit-serialRadioStringTx.png|''Program v blokovom jazyku pre vysielač''
Image:microbit-serialRadioStringRx|''a pre prijímač''
Image:microbit-serialRadioStringRx.png|''a pre prijímač''
</gallery>
</gallery>




<tabs>
<tabs>
<tab name="Javascript"><source lang="javascript">
<tab name="Javascript"><source lang="javascript">
radio.onReceivedString(function on_received_string(receivedString: string) {
    serial.writeLine(receivedString)
})
let AccX = 0
radio.setGroup(1)
basic.forever(function on_forever() {
   
    AccX = input.acceleration(Dimension.X)
    radio.sendNumber(AccX)
    basic.pause(100)
})
    
    
</source></tab>
</source></tab>
<tab name="MS Python"><source lang="python" style="background: LightBlue;">
<tab name="MS Python"><source lang="python" style="background: LightBlue;">
def on_received_number(receivedNumber):
    serial.write_line("" + str((receivedNumber)))
radio.on_received_number(on_received_number)
def on_received_string(receivedString):
    serial.write_line(receivedString)
radio.on_received_string(on_received_string)
AccX = 0
radio.set_group(1)
def on_forever():
    radio.send_string("" + str(control.millis()) + "," + str(AccX))
    led.toggle(2, 2)
    basic.pause(100)
basic.forever(on_forever)
def on_forever2():
    global AccX
    AccX = input.acceleration(Dimension.X)
    radio.send_number(AccX)
    basic.pause(100)
basic.forever(on_forever2)


</source></tab>
</source></tab>

Aktuálna revízia z 17:53, 18. marec 2024

Toto je základný príklad na bezdrôtový prenos dát. Jeden micro:bit je napájaný z batérie a vykonáva samotné merania, tie pošle cez rádiový kanál druhému micro:bitu, ktorý je pripojený k počítaču a všetky dáta, ktoré prijme hneď prepošle po sériovej linke (resp. USB) do počítača, kde ich môžeme sledovať buď priamo v MakeCode prostredí, alebo inom terminálovom programe.



radio.onReceivedNumber(function on_received_number(receivedNumber: number) {
    serial.writeLine("" + ("" + receivedNumber))
})

let AccX = 0
radio.setGroup(1)

basic.forever(function on_forever() {
    radio.sendString("" + ("" + control.millis()) + "," + ("" + AccX))
    led.toggle(2, 2)
    basic.pause(100)
})
def on_received_number(receivedNumber):
    serial.write_line("" + str((receivedNumber)))
radio.on_received_number(on_received_number)

AccX = 0
radio.set_group(1)

def on_forever():
    global AccX
    AccX = input.acceleration(Dimension.X)
    radio.send_number(AccX)
    basic.pause(100)
basic.forever(on_forever)
ToDo


Nasleduje drobná modifikácia, kde nebudeme posielať číslo, ale celý reťazec s viacerými meraniami, v tomto prípade oddelenými čiarkou.



radio.onReceivedString(function on_received_string(receivedString: string) {
    serial.writeLine(receivedString)
})

let AccX = 0
radio.setGroup(1)

basic.forever(function on_forever() {
    
    AccX = input.acceleration(Dimension.X)
    radio.sendNumber(AccX)
    basic.pause(100)
})
def on_received_number(receivedNumber):
    serial.write_line("" + str((receivedNumber)))
radio.on_received_number(on_received_number)

def on_received_string(receivedString):
    serial.write_line(receivedString)
radio.on_received_string(on_received_string)

AccX = 0
radio.set_group(1)

def on_forever():
    radio.send_string("" + str(control.millis()) + "," + str(AccX))
    led.toggle(2, 2)
    basic.pause(100)
basic.forever(on_forever)

def on_forever2():
    global AccX
    AccX = input.acceleration(Dimension.X)
    radio.send_number(AccX)
    basic.pause(100)
basic.forever(on_forever2)
ToDo


Späť na zoznam príkladov....