From 08ace788c387291f0ac3d2eb863b282db06e834d Mon Sep 17 00:00:00 2001
From: imaonenub <93632222+imaonenub@users.noreply.github.com>
Date: Mon, 6 Nov 2023 12:58:53 +0700
Subject: [PATCH] Update main.blocks, main.ts
---
main.blocks | 8 +++++++-
main.ts | 55 ++++++++++++++++++++++++-----------------------------
2 files changed, 32 insertions(+), 31 deletions(-)
diff --git a/main.blocks b/main.blocks
index 1644386..29fdd8a 100644
--- a/main.blocks
+++ b/main.blocks
@@ -1 +1,7 @@
-SerialDatastripafter 2s da code will rungithub.com/imaonenub/ai-serial-connectionThis block listens to the website for your class names, and saves them as a variableDelimiters.NewLineYour Device Connected2000SerialData0Delimiters.NewLineThis If statement checks that variable with the class name, and if it matches the class name you entered, it will activate the code within that blockTRUEEQSerialData1DigitalPin.P015000DigitalPin.P00EQSerialData2DigitalPin.P015000DigitalPin.P00EQSerialData3DigitalPin.P015000DigitalPin.P00EQSerialData4DigitalPin.P015000DigitalPin.P00strip0DigitalPin.P0NeoPixelMode.RGB30TenKeed Bin StartingIconNames.Yes1000stripNeoPixelColors.Whiteshow title;loading..500loading..SerialDatastripNeoPixelColors.Greenstrip500clearscreen cleaning100stripTRUELT0Environment.Distance_Unit.Distance_Unit_cmDigitalPin.P510stripNeoPixelColors.GreenstripopeningDigitalPin.P015000closingDigitalPin.P00
\ No newline at end of file
+SerialDatastripgithub.com/imaonenub/ai-serial-connectionafter 2s da code will runThis block listens to the website for your class names, and saves them as a variableDelimiters.NewLineSerialData0Delimiters.NewLineThis If statement checks that variable with the class name, and if it matches the class name you entered, it will activate the code within that blockTRUEEQSerialDatabiowasteservos.P1455000servos.P190servos.P1EQSerialDatarecycleDigitalPin.P215000DigitalPin.P20EQSerialDatadangerousDigitalPin.P315000DigitalPin.P30EQSerialDatanormalwasteDigitalPin.P415000DigitalPin.P40strip0DigitalPin.P5NeoPixelMode.RGB30show title;stripNeoPixelColors.Greenstrip500`
+ # # # # #
+ # . # . #
+ # # # # #
+ # # . . #
+ # . # . .
+ `clear100stripTRUEGT0DigitalPin.P61stripNeoPixelColors.Whitestripservos.P0905000servos.P090
\ No newline at end of file
diff --git a/main.ts b/main.ts
index 8e596c0..661416e 100644
--- a/main.ts
+++ b/main.ts
@@ -1,5 +1,4 @@
function clear () {
- basic.showString("screen cleaning")
basic.pause(100)
basic.clearScreen()
strip.clear()
@@ -10,39 +9,41 @@ function clear () {
*/
// This block listens to the website for your class names, and saves them as a variable
serial.onDataReceived(serial.delimiters(Delimiters.NewLine), function () {
- basic.showString("Your Device Connected")
- basic.pause(2000)
SerialData = serial.readUntil(serial.delimiters(Delimiters.NewLine))
// This If statement checks that variable with the class name, and if it matches the class name you entered, it will activate the code within that block
- if (SerialData == "1") {
- show_title()
- pins.digitalWritePin(DigitalPin.P0, 1)
+ if (SerialData == "biowaste") {
+ servos.P1.setAngle(45)
basic.pause(5000)
- pins.digitalWritePin(DigitalPin.P0, 0)
- } else if (SerialData == "2") {
+ servos.P1.setAngle(90)
+ servos.P1.stop()
+ } else if (SerialData == "recycle") {
show_title()
- pins.digitalWritePin(DigitalPin.P0, 1)
+ pins.digitalWritePin(DigitalPin.P2, 1)
basic.pause(5000)
- pins.digitalWritePin(DigitalPin.P0, 0)
- } else if (SerialData == "3") {
+ pins.digitalWritePin(DigitalPin.P2, 0)
+ } else if (SerialData == "dangerous") {
show_title()
- pins.digitalWritePin(DigitalPin.P0, 1)
+ pins.digitalWritePin(DigitalPin.P3, 1)
basic.pause(5000)
- pins.digitalWritePin(DigitalPin.P0, 0)
- } else if (SerialData == "4") {
+ pins.digitalWritePin(DigitalPin.P3, 0)
+ } else if (SerialData == "normalwaste") {
show_title()
- pins.digitalWritePin(DigitalPin.P0, 1)
+ pins.digitalWritePin(DigitalPin.P4, 1)
basic.pause(5000)
- pins.digitalWritePin(DigitalPin.P0, 0)
+ pins.digitalWritePin(DigitalPin.P4, 0)
}
})
function show_title () {
- basic.showString("loading..")
- basic.pause(500)
- basic.showString(SerialData)
strip.showColor(neopixel.colors(NeoPixelColors.Green))
strip.show()
basic.pause(500)
+ basic.showLeds(`
+ # # # # #
+ # . # . #
+ # # # # #
+ # # . . #
+ # . # . .
+ `)
clear()
}
/**
@@ -50,22 +51,16 @@ function show_title () {
*/
let SerialData = ""
let strip: neopixel.Strip = null
-strip = neopixel.create(DigitalPin.P0, 30, NeoPixelMode.RGB)
+strip = neopixel.create(DigitalPin.P5, 30, NeoPixelMode.RGB)
serial.redirectToUSB()
-basic.showString("TenKeed Bin Starting")
-basic.showIcon(IconNames.Yes)
-basic.pause(1000)
-strip.showColor(neopixel.colors(NeoPixelColors.White))
clear()
basic.forever(function () {
- if (Environment.sonarbit_distance(Environment.Distance_Unit.Distance_Unit_cm, DigitalPin.P5) < 10) {
- strip.showColor(neopixel.colors(NeoPixelColors.Green))
+ if (grove.measureInInchesV2(DigitalPin.P6) > 1) {
+ strip.showColor(neopixel.colors(NeoPixelColors.White))
strip.show()
- basic.showString("opening")
- pins.digitalWritePin(DigitalPin.P0, 1)
+ servos.P0.setAngle(90)
basic.pause(5000)
- basic.showString("closing")
- pins.digitalWritePin(DigitalPin.P0, 0)
+ servos.P0.setAngle(90)
clear()
}
})