Skip to content

Commit

Permalink
Merge pull request #24 from Adam0Brien/sensor-pod-comms
Browse files Browse the repository at this point in the history
feat: Added Sensor Pod to USV Comms.
  • Loading branch information
Adam O'Brien authored Apr 4, 2024
2 parents f416724 + d608075 commit 79501a2
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 32 deletions.
57 changes: 57 additions & 0 deletions USV/Sensor-Pod-Comms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Starter Implementation
// Change on button A and B pressed to physical circuit
input.onButtonPressed(Button.A, function () {
isSubmerged = 0
})
input.onButtonPressed(Button.B, function () {
isSubmerged = 1
})
let isSubmerged = 0
radio.setGroup(213)
basic.showIcon(IconNames.Yes)
USVSensorPod.initLocalDisplay()
let ph_list: number[] = []
let light_list: number[] = []
let temp_list: number[] = []
isSubmerged = 1
basic.forever(function () {
USVSensorPod.ShowString("Temp:" + USVSensorPod.calculateTempC() + "°C", 0, 0)
USVSensorPod.ShowString("pH:" + USVSensorPod.calculatePh(), 0, 1)
})
basic.forever(function () {
if (isSubmerged == 1) {
ph_list.push(USVSensorPod.calculatePh())
temp_list.push(USVSensorPod.calculateTempC())
light_list.push(USVSensorPod.getLight())
basic.pause(100)
led.toggle(4, 0)
}
})
basic.forever(function () {
if (isSubmerged == 0) {
for (let value of ph_list) {
radio.sendValue("pH", value)
basic.pause(1000)
ph_list.removeAt(ph_list.indexOf(value))
}
}
})
basic.forever(function () {
if (isSubmerged == 0) {
for (let value of light_list) {
radio.sendValue("light", value)
basic.pause(1000)
led.toggle(0, 0)
light_list.removeAt(light_list.indexOf(value))
}
}
})
basic.forever(function () {
if (isSubmerged == 0) {
for (let value of temp_list) {
radio.sendValue("tempC", value)
basic.pause(100)
temp_list.removeAt(temp_list.indexOf(value))
}
}
})
58 changes: 26 additions & 32 deletions USV/USV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace USV {
let Arm = 1
}

//% blockId=1disarmUSV
//% blockId=disarmUSV
//% block="Disarm USV"
//% weight=50
//% color=#2bd9ad
Expand Down Expand Up @@ -197,44 +197,38 @@ namespace USV {
}
}

//% blockId=getTempC
//% block="Sensor Pod Temperature °C"
//% subcategory=Sensor Pod
//% color=#442FDE
//% group="Sensors"
export function getTempC(): number {
// Ask sensor pod for temperature through radio
return 0
}

//% blockId=getTempF
//% block="Sensor Pod Temperature °F"
//% subcategory=Sensor Pod
//% color=#442FDE
//% group="Sensors"
export function getTempF(): number {
// Ask sensor pod for temperature
return 0
export enum SensorType {
pH = 0,
tempC = 1,
light = 2,
}

//% blockId=getPh
//% block="Sensor Pod pH"
//% subcategory=Sensor Pod
//% color=#442FDE
//% group="Sensors"
export function getPh(): number {
// Ask sensor pod for pH
return 0
function sensorListener(sensorType: SensorType) {
let sensorName: string;

if(sensorType == 0) {
sensorName = "pH";
} else if (sensorType == 1){
sensorName = "tempC";
} else if (sensorType == 2) {
sensorName = "light";
}

radio.onReceivedValue(function (name, value) {
if (name == sensorName) {
serial.writeValue(name, value);
}
});
}

//% blockId=Sensor Pod Light
//% block="Sensor Pod Light"
//% subcategory=Sensor Pod
//% blockId="sensorListenerBlock"
//% block="Listen for Sensor Pod |%SensorType value"
//% subcategory="Sensors"
//% color=#442FDE
//% group="Sensors"
export function getLight(): number {
// Ask sensor pod for LDR reading
return 0
export function sensorListenerBlock(sensorType: SensorType): void {
sensorListener(sensorType);
}


Expand Down

0 comments on commit 79501a2

Please sign in to comment.