change strip-->GroveModule
This commit is contained in:
parent
dab64d607a
commit
f55c6e4854
@ -16,13 +16,13 @@
|
|||||||
"grove.measureInCentimeters|block": "Ultraschallsensor (in cm) an |%pin",
|
"grove.measureInCentimeters|block": "Ultraschallsensor (in cm) an |%pin",
|
||||||
"grove.measureInInches|block": "Ultraschallsensor (in inch) an |%pin",
|
"grove.measureInInches|block": "Ultraschallsensor (in inch) an |%pin",
|
||||||
"grove.createDisplay|block": "4-Ziffern Display an|%clkPin|und|%dataPin",
|
"grove.createDisplay|block": "4-Ziffern Display an|%clkPin|und|%dataPin",
|
||||||
"grove.PAJ7620.init|block": "%strip|initialisiere den Gestensensor",
|
"grove.PAJ7620.init|block": "%GroveModule|initialisiere den Gestensensor",
|
||||||
"grove.PAJ7620.read|block": "%strip|erkenne Geste",
|
"grove.PAJ7620.read|block": "%GroveModule|erkenne Geste",
|
||||||
"grove.TM1637.show|block": "%strip|zeige Zahl|%dispData|",
|
"grove.TM1637.show|block": "%GroveModule|zeige Zahl|%dispData|",
|
||||||
"grove.TM1637.set|block": "%strip|setze Helligkeit auf|%level|",
|
"grove.TM1637.set|block": "%GroveModule|setze Helligkeit auf|%level|",
|
||||||
"grove.TM1637.bit|block": "%strip|zeige Ziffer|%dispData|an Stelle|%bitAddr|",
|
"grove.TM1637.bit|block": "%GroveModule|zeige Ziffer|%dispData|an Stelle|%bitAddr|",
|
||||||
"grove.TM1637.point|block": "%strip|schalte Kommapunkt|%point|",
|
"grove.TM1637.point|block": "%GroveModule|schalte Kommapunkt|%point|",
|
||||||
"grove.TM1637.clear|block": "%strip|lösche 4-Ziffern Display",
|
"grove.TM1637.clear|block": "%GroveModule|lösche 4-Ziffern Display",
|
||||||
"GroveJoystickKey.None|block": "Keiner",
|
"GroveJoystickKey.None|block": "Keiner",
|
||||||
"GroveJoystickKey.Right|block": "Rechts",
|
"GroveJoystickKey.Right|block": "Rechts",
|
||||||
"GroveJoystickKey.Left|block": "Links",
|
"GroveJoystickKey.Left|block": "Links",
|
||||||
@ -33,7 +33,7 @@
|
|||||||
"GroveJoystickKey.LL|block": "Unten links",
|
"GroveJoystickKey.LL|block": "Unten links",
|
||||||
"GroveJoystickKey.LR|block": "Unten rechts",
|
"GroveJoystickKey.LR|block": "Unten rechts",
|
||||||
"GroveJoystickKey.Press|block": "Gedrückt",
|
"GroveJoystickKey.Press|block": "Gedrückt",
|
||||||
"grove.strip.read|block": "%strip|lies Position von Joystick an|%xpin|und|%ypin",
|
"grove.strip.read|block": "%GroveModule|lies Position von Joystick an|%xpin|und|%ypin",
|
||||||
"grove.onJoystick|block": "wenn Grove - Joysticktaste|%key an|%xpin|und|%ypin",
|
"grove.onJoystick|block": "wenn Grove - Joysticktaste|%key an|%xpin|und|%ypin",
|
||||||
"grove.getJoystick|block": "hole Joysticktaste an|%xpin|und|%ypin"
|
"grove.getJoystick|block": "hole Joysticktaste an|%xpin|und|%ypin"
|
||||||
}
|
}
|
191
main.ts
191
main.ts
@ -29,7 +29,7 @@ const initRegisterArray: number[] = [
|
|||||||
0x7C, 0x84, 0x7D, 0x03, 0x7E, 0x01
|
0x7C, 0x84, 0x7D, 0x03, 0x7E, 0x01
|
||||||
];
|
];
|
||||||
|
|
||||||
let TubeTab: number[] = [
|
let TubeTab: number [] = [
|
||||||
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
|
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
|
||||||
0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
|
0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
|
||||||
];
|
];
|
||||||
@ -156,41 +156,41 @@ namespace grove {
|
|||||||
switch (data) {
|
switch (data) {
|
||||||
case 0x01:
|
case 0x01:
|
||||||
result = GroveGesture.Right;
|
result = GroveGesture.Right;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x02:
|
case 0x02:
|
||||||
result = GroveGesture.Left;
|
result = GroveGesture.Left;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x04:
|
case 0x04:
|
||||||
result = GroveGesture.Up;
|
result = GroveGesture.Up;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x08:
|
case 0x08:
|
||||||
result = GroveGesture.Down;
|
result = GroveGesture.Down;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x10:
|
case 0x10:
|
||||||
result = GroveGesture.Forward;
|
result = GroveGesture.Forward;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x20:
|
case 0x20:
|
||||||
result = GroveGesture.Backward;
|
result = GroveGesture.Backward;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x40:
|
case 0x40:
|
||||||
result = GroveGesture.Clockwise;
|
result = GroveGesture.Clockwise;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x80:
|
case 0x80:
|
||||||
result = GroveGesture.Anticlockwise;
|
result = GroveGesture.Anticlockwise;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
data = this.paj7620ReadReg(0x44);
|
data = this.paj7620ReadReg(0x44);
|
||||||
if (data == 0x01)
|
if (data == 0x01)
|
||||||
result = GroveGesture.Wave;
|
result = GroveGesture.Wave;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -200,17 +200,20 @@ namespace grove {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class TM1637 {
|
export class TM1637
|
||||||
|
{
|
||||||
clkPin: DigitalPin;
|
clkPin: DigitalPin;
|
||||||
dataPin: DigitalPin;
|
dataPin: DigitalPin;
|
||||||
brightnessLevel: number;
|
brightnessLevel: number;
|
||||||
pointFlag: boolean;
|
pointFlag: boolean;
|
||||||
buf: Buffer;
|
buf: Buffer;
|
||||||
|
|
||||||
private writeByte(wrData: number) {
|
private writeByte(wrData: number)
|
||||||
for (let i = 0; i < 8; i++) {
|
{
|
||||||
|
for(let i = 0; i < 8; i ++)
|
||||||
|
{
|
||||||
pins.digitalWritePin(this.clkPin, 0);
|
pins.digitalWritePin(this.clkPin, 0);
|
||||||
if (wrData & 0x01) pins.digitalWritePin(this.dataPin, 1);
|
if(wrData & 0x01)pins.digitalWritePin(this.dataPin, 1);
|
||||||
else pins.digitalWritePin(this.dataPin, 0);
|
else pins.digitalWritePin(this.dataPin, 0);
|
||||||
wrData >>= 1;
|
wrData >>= 1;
|
||||||
pins.digitalWritePin(this.clkPin, 1);
|
pins.digitalWritePin(this.clkPin, 1);
|
||||||
@ -221,27 +224,30 @@ namespace grove {
|
|||||||
pins.digitalWritePin(this.clkPin, 1);
|
pins.digitalWritePin(this.clkPin, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private start() {
|
private start()
|
||||||
|
{
|
||||||
pins.digitalWritePin(this.clkPin, 1);
|
pins.digitalWritePin(this.clkPin, 1);
|
||||||
pins.digitalWritePin(this.dataPin, 1);
|
pins.digitalWritePin(this.dataPin, 1);
|
||||||
pins.digitalWritePin(this.dataPin, 0);
|
pins.digitalWritePin(this.dataPin, 0);
|
||||||
pins.digitalWritePin(this.clkPin, 0);
|
pins.digitalWritePin(this.clkPin, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private stop() {
|
private stop()
|
||||||
|
{
|
||||||
pins.digitalWritePin(this.clkPin, 0);
|
pins.digitalWritePin(this.clkPin, 0);
|
||||||
pins.digitalWritePin(this.dataPin, 0);
|
pins.digitalWritePin(this.dataPin, 0);
|
||||||
pins.digitalWritePin(this.clkPin, 1);
|
pins.digitalWritePin(this.clkPin, 1);
|
||||||
pins.digitalWritePin(this.dataPin, 1);
|
pins.digitalWritePin(this.dataPin, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private coding(dispData: number): number {
|
private coding(dispData: number): number
|
||||||
|
{
|
||||||
let pointData = 0;
|
let pointData = 0;
|
||||||
|
|
||||||
if (this.pointFlag == true) pointData = 0x80;
|
if(this.pointFlag == true)pointData = 0x80;
|
||||||
else if (this.pointFlag == false) pointData = 0;
|
else if(this.pointFlag == false)pointData = 0;
|
||||||
|
|
||||||
if (dispData == 0x7f) dispData = 0x00 + pointData;
|
if(dispData == 0x7f)dispData = 0x00 + pointData;
|
||||||
else dispData = TubeTab[dispData] + pointData;
|
else dispData = TubeTab[dispData] + pointData;
|
||||||
|
|
||||||
return dispData;
|
return dispData;
|
||||||
@ -251,61 +257,82 @@ namespace grove {
|
|||||||
* Show a 4 digits number on display
|
* Show a 4 digits number on display
|
||||||
* @param dispData value of number
|
* @param dispData value of number
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_tm1637_display_number block="%strip|show number|%dispData"
|
//% blockId=grove_tm1637_display_number block="%GroveModule|show number|%dispData"
|
||||||
show(dispData: number) {
|
show(dispData: number)
|
||||||
if (dispData < 10) {
|
{
|
||||||
|
let compare_01:number = dispData % 100;
|
||||||
|
let compare_001:number = dispData % 1000;
|
||||||
|
|
||||||
|
if(dispData < 10)
|
||||||
|
{
|
||||||
this.bit(dispData, 3);
|
this.bit(dispData, 3);
|
||||||
this.bit(0x7f, 2);
|
this.bit(0x7f, 2);
|
||||||
this.bit(0x7f, 1);
|
this.bit(0x7f, 1);
|
||||||
this.bit(0x7f, 0);
|
this.bit(0x7f, 0);
|
||||||
|
|
||||||
this.buf[3] = dispData;
|
|
||||||
this.buf[2] = 0x7f;
|
|
||||||
this.buf[1] = 0x7f;
|
|
||||||
this.buf[0] = 0x7f;
|
|
||||||
}
|
}
|
||||||
else if (dispData < 100) {
|
else if(dispData < 100)
|
||||||
|
{
|
||||||
this.bit(dispData % 10, 3);
|
this.bit(dispData % 10, 3);
|
||||||
this.bit((dispData / 10) % 10, 2);
|
if(dispData > 90){
|
||||||
|
this.bit(9, 2);
|
||||||
|
} else{
|
||||||
|
this.bit(Math.floor(dispData / 10) % 10, 2);
|
||||||
|
}
|
||||||
|
|
||||||
this.bit(0x7f, 1);
|
this.bit(0x7f, 1);
|
||||||
this.bit(0x7f, 0);
|
this.bit(0x7f, 0);
|
||||||
|
|
||||||
this.buf[3] = dispData % 10;
|
|
||||||
this.buf[2] = (dispData / 10) % 10;
|
|
||||||
this.buf[1] = 0x7f;
|
|
||||||
this.buf[0] = 0x7f;
|
|
||||||
}
|
}
|
||||||
else if (dispData < 1000) {
|
else if(dispData < 1000)
|
||||||
|
{
|
||||||
this.bit(dispData % 10, 3);
|
this.bit(dispData % 10, 3);
|
||||||
this.bit((dispData / 10) % 10, 2);
|
if(compare_01 > 90){
|
||||||
this.bit((dispData / 100) % 10, 1);
|
this.bit(9, 2);
|
||||||
|
} else{
|
||||||
|
this.bit(Math.floor(dispData / 10) % 10, 2);
|
||||||
|
}
|
||||||
|
if(compare_001 > 900){
|
||||||
|
this.bit(9, 1);
|
||||||
|
} else{
|
||||||
|
this.bit(Math.floor(dispData / 100) % 10, 1);
|
||||||
|
}
|
||||||
this.bit(0x7f, 0);
|
this.bit(0x7f, 0);
|
||||||
|
|
||||||
this.buf[3] = dispData % 10;
|
|
||||||
this.buf[2] = (dispData / 10) % 10;
|
|
||||||
this.buf[1] = (dispData / 100) % 10;
|
|
||||||
this.buf[0] = 0x7f;
|
|
||||||
}
|
}
|
||||||
else {
|
else if(dispData < 10000)
|
||||||
|
{
|
||||||
this.bit(dispData % 10, 3);
|
this.bit(dispData % 10, 3);
|
||||||
this.bit((dispData / 10) % 10, 2);
|
if(compare_01 > 90){
|
||||||
this.bit((dispData / 100) % 10, 1);
|
this.bit(9, 2);
|
||||||
this.bit((dispData / 1000) % 10, 0);
|
} else{
|
||||||
|
this.bit(Math.floor(dispData / 10) % 10, 2);
|
||||||
this.buf[3] = dispData % 10;
|
}
|
||||||
this.buf[2] = (dispData / 10) % 10;
|
if(compare_001 > 900){
|
||||||
this.buf[1] = (dispData / 100) % 10;
|
this.bit(9, 1);
|
||||||
this.buf[0] = (dispData / 1000) % 10;
|
} else{
|
||||||
|
this.bit(Math.floor(dispData / 100) % 10, 1);
|
||||||
|
}
|
||||||
|
if(dispData > 9000){
|
||||||
|
this.bit(9, 0);
|
||||||
|
} else{
|
||||||
|
this.bit(Math.floor(dispData / 1000) % 10, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.bit(9, 3);
|
||||||
|
this.bit(9, 2);
|
||||||
|
this.bit(9, 1);
|
||||||
|
this.bit(9, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the brightness level of display at from 0 to 7
|
* Set the brightness level of display at from 0 to 7
|
||||||
* @param level value of brightness level
|
* @param level value of brightness light level
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_tm1637_set_display_level block="%strip|brightness level to|%level"
|
//% blockId=grove_tm1637_set_display_level block="%GroveModule|brightness level to|%level"
|
||||||
//% level.min=0 level.max=7
|
//% level.min=0 level.max=7
|
||||||
set(level: number) {
|
set(level: number)
|
||||||
|
{
|
||||||
this.brightnessLevel = level;
|
this.brightnessLevel = level;
|
||||||
|
|
||||||
this.bit(this.buf[0], 0x00);
|
this.bit(this.buf[0], 0x00);
|
||||||
@ -319,12 +346,14 @@ namespace grove {
|
|||||||
* @param dispData value of number
|
* @param dispData value of number
|
||||||
* @param bitAddr value of bit number
|
* @param bitAddr value of bit number
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_tm1637_display_bit block="%strip|show single number|%dispData|at digit|%bitAddr"
|
//% blockId=grove_tm1637_display_bit block="%GroveModule|show single number|%dispData|at digit|%bitAddr"
|
||||||
//% dispData.min=0 dispData.max=9
|
//% dispData.min=0 dispData.max=9
|
||||||
//% bitAddr.min=0 bitAddr.max=3
|
//% bitAddr.min=0 bitAddr.max=3
|
||||||
//% advanced=true
|
//% advanced=true
|
||||||
bit(dispData: number, bitAddr: number) {
|
bit(dispData: number, bitAddr: number)
|
||||||
if ((dispData == 0x7f) || ((dispData <= 9) && (bitAddr <= 3))) {
|
{
|
||||||
|
if((dispData == 0x7f) || ((dispData <= 9) && (bitAddr <= 3)))
|
||||||
|
{
|
||||||
let segData = 0;
|
let segData = 0;
|
||||||
|
|
||||||
segData = this.coding(dispData);
|
segData = this.coding(dispData);
|
||||||
@ -347,9 +376,10 @@ namespace grove {
|
|||||||
* Turn on or off the colon point on Grove - 4-Digit Display
|
* Turn on or off the colon point on Grove - 4-Digit Display
|
||||||
* @param pointEn value of point switch
|
* @param pointEn value of point switch
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_tm1637_display_point block="%strip|turn|%point|colon point"
|
//% blockId=grove_tm1637_display_point block="%GroveModul|turn|%point|colon point"
|
||||||
//% advanced=true
|
//% advanced=true
|
||||||
point(point: boolean) {
|
point(point: boolean)
|
||||||
|
{
|
||||||
this.pointFlag = point;
|
this.pointFlag = point;
|
||||||
|
|
||||||
this.bit(this.buf[0], 0x00);
|
this.bit(this.buf[0], 0x00);
|
||||||
@ -361,9 +391,10 @@ namespace grove {
|
|||||||
/**
|
/**
|
||||||
* Clear the display
|
* Clear the display
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_tm1637_display_clear block="%strip|clear"
|
//% blockId=grove_tm1637_display_clear block="%GroveModul|clear"
|
||||||
//% advanced=true
|
//% advanced=true
|
||||||
clear() {
|
clear()
|
||||||
|
{
|
||||||
this.bit(0x7f, 0x00);
|
this.bit(0x7f, 0x00);
|
||||||
this.bit(0x7f, 0x01);
|
this.bit(0x7f, 0x01);
|
||||||
this.bit(0x7f, 0x02);
|
this.bit(0x7f, 0x02);
|
||||||
@ -372,13 +403,14 @@ namespace grove {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class GroveJoystick {
|
export class GroveJoystick
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Detect position from Grove - Thumb Joystick
|
* Detect position from Grove - Thumb Joystick
|
||||||
* @param xPin
|
* @param xPin
|
||||||
* @param yPin
|
* @param yPin
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_joystick_read block="%strip|read position of joystick|%xpin|and|%ypin"
|
//% blockId=grove_joystick_read block="%GroveModul|read position of joystick at|%xpin|and|%ypin"
|
||||||
//% advanced=true
|
//% advanced=true
|
||||||
read(xPin: AnalogPin, yPin: AnalogPin): number {
|
read(xPin: AnalogPin, yPin: AnalogPin): number {
|
||||||
let xdata = 0, ydata = 0, result = 0;
|
let xdata = 0, ydata = 0, result = 0;
|
||||||
@ -405,7 +437,7 @@ namespace grove {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = GroveJoystickKey.None;
|
result = GroveJoystickKey.None;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -424,7 +456,10 @@ namespace grove {
|
|||||||
* @param pin signal pin of ultrasonic ranger module
|
* @param pin signal pin of ultrasonic ranger module
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_ultrasonic_centimeters block="Ultrasonic Sensor (in cm) at|%pin"
|
//% blockId=grove_ultrasonic_centimeters block="Ultrasonic Sensor (in cm) at|%pin"
|
||||||
export function measureInCentimeters(pin: DigitalPin): number {
|
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
|
||||||
|
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250"
|
||||||
|
export function measureInCentimeters(pin: DigitalPin): number
|
||||||
|
{
|
||||||
let duration = 0;
|
let duration = 0;
|
||||||
let RangeInCentimeters = 0;
|
let RangeInCentimeters = 0;
|
||||||
|
|
||||||
@ -437,7 +472,7 @@ namespace grove {
|
|||||||
|
|
||||||
RangeInCentimeters = duration * 153 / 29 / 2 / 100;
|
RangeInCentimeters = duration * 153 / 29 / 2 / 100;
|
||||||
|
|
||||||
if (RangeInCentimeters > 0) distanceBackup = RangeInCentimeters;
|
if(RangeInCentimeters > 0) distanceBackup = RangeInCentimeters;
|
||||||
else RangeInCentimeters = distanceBackup;
|
else RangeInCentimeters = distanceBackup;
|
||||||
|
|
||||||
basic.pause(50);
|
basic.pause(50);
|
||||||
@ -450,7 +485,10 @@ namespace grove {
|
|||||||
* @param pin signal pin of ultrasonic ranger module
|
* @param pin signal pin of ultrasonic ranger module
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_ultrasonic_inches block="Ultrasonic Sensor (in inch) at|%pin"
|
//% blockId=grove_ultrasonic_inches block="Ultrasonic Sensor (in inch) at|%pin"
|
||||||
export function measureInInches(pin: DigitalPin): number {
|
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
|
||||||
|
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250"
|
||||||
|
export function measureInInches(pin: DigitalPin): number
|
||||||
|
{
|
||||||
let duration = 0;
|
let duration = 0;
|
||||||
let RangeInInches = 0;
|
let RangeInInches = 0;
|
||||||
|
|
||||||
@ -463,7 +501,7 @@ namespace grove {
|
|||||||
|
|
||||||
RangeInInches = duration * 153 / 74 / 2 / 100;
|
RangeInInches = duration * 153 / 74 / 2 / 100;
|
||||||
|
|
||||||
if (RangeInInches > 0) distanceBackup = RangeInInches;
|
if(RangeInInches > 0) distanceBackup = RangeInInches;
|
||||||
else RangeInInches = distanceBackup;
|
else RangeInInches = distanceBackup;
|
||||||
|
|
||||||
basic.pause(50);
|
basic.pause(50);
|
||||||
@ -477,7 +515,12 @@ namespace grove {
|
|||||||
* @param dataPin value of data pin number
|
* @param dataPin value of data pin number
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_tm1637_create block="4-Digit Display at|%clkPin|and|%dataPin"
|
//% blockId=grove_tm1637_create block="4-Digit Display at|%clkPin|and|%dataPin"
|
||||||
export function createDisplay(clkPin: DigitalPin, dataPin: DigitalPin): TM1637 {
|
//% clkPin.fieldEditor="gridpicker" clkPin.fieldOptions.columns=4
|
||||||
|
//% clkPin.fieldOptions.tooltips="false" clkPin.fieldOptions.width="250"
|
||||||
|
//% dataPin.fieldEditor="gridpicker" dataPin.fieldOptions.columns=4
|
||||||
|
//% dataPin.fieldOptions.tooltips="false" dataPin.fieldOptions.width="250"
|
||||||
|
export function createDisplay(clkPin: DigitalPin, dataPin: DigitalPin): TM1637
|
||||||
|
{
|
||||||
let display = new TM1637();
|
let display = new TM1637();
|
||||||
|
|
||||||
display.buf = pins.createBuffer(4);
|
display.buf = pins.createBuffer(4);
|
||||||
@ -513,7 +556,7 @@ namespace grove {
|
|||||||
* get Joystick key
|
* get Joystick key
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_getjoystick block="get joystick key at|%xpin|and|%xpin"
|
//% blockId=grove_getjoystick block="get joystick key at|%xpin|and|%ypin"
|
||||||
export function getJoystick(xpin: AnalogPin, ypin: AnalogPin): number {
|
export function getJoystick(xpin: AnalogPin, ypin: AnalogPin): number {
|
||||||
return joystick.read(xpin, ypin);
|
return joystick.read(xpin, ypin);
|
||||||
}
|
}
|
||||||
@ -529,7 +572,7 @@ namespace grove {
|
|||||||
control.onEvent(gestureEventId, gesture, handler);
|
control.onEvent(gestureEventId, gesture, handler);
|
||||||
paj7620.init();
|
paj7620.init();
|
||||||
control.inBackground(() => {
|
control.inBackground(() => {
|
||||||
while (true) {
|
while(true) {
|
||||||
const gesture = paj7620.read();
|
const gesture = paj7620.read();
|
||||||
if (gesture != lastGesture) {
|
if (gesture != lastGesture) {
|
||||||
lastGesture = gesture;
|
lastGesture = gesture;
|
||||||
@ -548,11 +591,11 @@ namespace grove {
|
|||||||
* @param ypin
|
* @param ypin
|
||||||
* @param handler code to run
|
* @param handler code to run
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_joystick_create_event block="on Key|%key at|%xpin|and|%ypin"
|
//% blockId=grove_joystick_create_event block="on Key|%key at |%xpin|and|%ypin"
|
||||||
export function onJoystick(key: GroveJoystickKey, xpin: AnalogPin, ypin: AnalogPin, handler: () => void) {
|
export function onJoystick(key: GroveJoystickKey, xpin: AnalogPin, ypin: AnalogPin, handler: () => void) {
|
||||||
control.onEvent(joystickEventID, key, handler);
|
control.onEvent(joystickEventID, key, handler);
|
||||||
control.inBackground(() => {
|
control.inBackground(() => {
|
||||||
while (true) {
|
while(true) {
|
||||||
const key = joystick.read(xpin, ypin);
|
const key = joystick.read(xpin, ypin);
|
||||||
if (key != lastJoystick) {
|
if (key != lastJoystick) {
|
||||||
lastJoystick = key;
|
lastJoystick = key;
|
||||||
|
Loading…
Reference in New Issue
Block a user