Aktualisierungen.
This commit is contained in:
parent
727ec603ad
commit
6c0783c5b5
@ -33,7 +33,7 @@
|
||||
"GroveJoystickKey.LL|block": "Unten links",
|
||||
"GroveJoystickKey.LR|block": "Unten rechts",
|
||||
"GroveJoystickKey.Press|block": "Gedrückt",
|
||||
"grove.read|block": "%strip|lies Position von Joystick|%xpin|und|%ypin",
|
||||
"grove.grove_joystick_read|block": "%strip|lies Position von Joystick an|%xpin|und|%ypin",
|
||||
"grove.onJoystick|block": "wenn Grove - Joysticktaste|%key",
|
||||
"grove.getJoystick|block": "hole Joysticktaste an|%xpin|und|%ypin"
|
||||
}
|
78
main.ts
78
main.ts
@ -29,7 +29,7 @@ const initRegisterArray: number[] = [
|
||||
0x7C, 0x84, 0x7D, 0x03, 0x7E, 0x01
|
||||
];
|
||||
|
||||
let TubeTab: number [] = [
|
||||
let TubeTab: number[] = [
|
||||
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
|
||||
0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
|
||||
];
|
||||
@ -200,20 +200,17 @@ namespace grove {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export class TM1637
|
||||
{
|
||||
export class TM1637 {
|
||||
clkPin: DigitalPin;
|
||||
dataPin: DigitalPin;
|
||||
brightnessLevel: number;
|
||||
pointFlag: boolean;
|
||||
buf: Buffer;
|
||||
|
||||
private writeByte(wrData: number)
|
||||
{
|
||||
for(let i = 0; i < 8; i ++)
|
||||
{
|
||||
private writeByte(wrData: number) {
|
||||
for (let i = 0; i < 8; i++) {
|
||||
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);
|
||||
wrData >>= 1;
|
||||
pins.digitalWritePin(this.clkPin, 1);
|
||||
@ -224,30 +221,27 @@ namespace grove {
|
||||
pins.digitalWritePin(this.clkPin, 1);
|
||||
}
|
||||
|
||||
private start()
|
||||
{
|
||||
private start() {
|
||||
pins.digitalWritePin(this.clkPin, 1);
|
||||
pins.digitalWritePin(this.dataPin, 1);
|
||||
pins.digitalWritePin(this.dataPin, 0);
|
||||
pins.digitalWritePin(this.clkPin, 0);
|
||||
}
|
||||
|
||||
private stop()
|
||||
{
|
||||
private stop() {
|
||||
pins.digitalWritePin(this.clkPin, 0);
|
||||
pins.digitalWritePin(this.dataPin, 0);
|
||||
pins.digitalWritePin(this.clkPin, 1);
|
||||
pins.digitalWritePin(this.dataPin, 1);
|
||||
}
|
||||
|
||||
private coding(dispData: number): number
|
||||
{
|
||||
private coding(dispData: number): number {
|
||||
let pointData = 0;
|
||||
|
||||
if(this.pointFlag == true)pointData = 0x80;
|
||||
else if(this.pointFlag == false)pointData = 0;
|
||||
if (this.pointFlag == true) pointData = 0x80;
|
||||
else if (this.pointFlag == false) pointData = 0;
|
||||
|
||||
if(dispData == 0x7f)dispData = 0x00 + pointData;
|
||||
if (dispData == 0x7f) dispData = 0x00 + pointData;
|
||||
else dispData = TubeTab[dispData] + pointData;
|
||||
|
||||
return dispData;
|
||||
@ -258,10 +252,8 @@ namespace grove {
|
||||
* @param dispData value of number
|
||||
*/
|
||||
//% blockId=grove_tm1637_display_number block="%strip|show number|%dispData"
|
||||
show(dispData: number)
|
||||
{
|
||||
if(dispData < 10)
|
||||
{
|
||||
show(dispData: number) {
|
||||
if (dispData < 10) {
|
||||
this.bit(dispData, 3);
|
||||
this.bit(0x7f, 2);
|
||||
this.bit(0x7f, 1);
|
||||
@ -272,8 +264,7 @@ namespace grove {
|
||||
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) % 10, 2);
|
||||
this.bit(0x7f, 1);
|
||||
@ -284,8 +275,7 @@ namespace grove {
|
||||
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) % 10, 2);
|
||||
this.bit((dispData / 100) % 10, 1);
|
||||
@ -296,8 +286,7 @@ namespace grove {
|
||||
this.buf[1] = (dispData / 100) % 10;
|
||||
this.buf[0] = 0x7f;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
this.bit(dispData % 10, 3);
|
||||
this.bit((dispData / 10) % 10, 2);
|
||||
this.bit((dispData / 100) % 10, 1);
|
||||
@ -316,8 +305,7 @@ namespace grove {
|
||||
*/
|
||||
//% blockId=grove_tm1637_set_display_level block="%strip|brightness level to|%level"
|
||||
//% level.min=0 level.max=7
|
||||
set(level: number)
|
||||
{
|
||||
set(level: number) {
|
||||
this.brightnessLevel = level;
|
||||
|
||||
this.bit(this.buf[0], 0x00);
|
||||
@ -335,10 +323,8 @@ namespace grove {
|
||||
//% dispData.min=0 dispData.max=9
|
||||
//% bitAddr.min=0 bitAddr.max=3
|
||||
//% advanced=true
|
||||
bit(dispData: number, bitAddr: number)
|
||||
{
|
||||
if((dispData == 0x7f) || ((dispData <= 9) && (bitAddr <= 3)))
|
||||
{
|
||||
bit(dispData: number, bitAddr: number) {
|
||||
if ((dispData == 0x7f) || ((dispData <= 9) && (bitAddr <= 3))) {
|
||||
let segData = 0;
|
||||
|
||||
segData = this.coding(dispData);
|
||||
@ -363,8 +349,7 @@ namespace grove {
|
||||
*/
|
||||
//% blockId=grove_tm1637_display_point block="%strip|turn|%point|colon point"
|
||||
//% advanced=true
|
||||
point(point: boolean)
|
||||
{
|
||||
point(point: boolean) {
|
||||
this.pointFlag = point;
|
||||
|
||||
this.bit(this.buf[0], 0x00);
|
||||
@ -378,8 +363,7 @@ namespace grove {
|
||||
*/
|
||||
//% blockId=grove_tm1637_display_clear block="%strip|clear"
|
||||
//% advanced=true
|
||||
clear()
|
||||
{
|
||||
clear() {
|
||||
this.bit(0x7f, 0x00);
|
||||
this.bit(0x7f, 0x01);
|
||||
this.bit(0x7f, 0x02);
|
||||
@ -388,8 +372,7 @@ namespace grove {
|
||||
}
|
||||
|
||||
|
||||
export class GroveJoystick
|
||||
{
|
||||
export class GroveJoystick {
|
||||
/**
|
||||
* Detect position from Grove - Thumb Joystick
|
||||
* @param xPin
|
||||
@ -441,8 +424,7 @@ namespace grove {
|
||||
* @param pin signal pin of ultrasonic ranger module
|
||||
*/
|
||||
//% blockId=grove_ultrasonic_centimeters block="Ultrasonic Sensor (in cm) at|%pin"
|
||||
export function measureInCentimeters(pin: DigitalPin): number
|
||||
{
|
||||
export function measureInCentimeters(pin: DigitalPin): number {
|
||||
let duration = 0;
|
||||
let RangeInCentimeters = 0;
|
||||
|
||||
@ -455,7 +437,7 @@ namespace grove {
|
||||
|
||||
RangeInCentimeters = duration * 153 / 29 / 2 / 100;
|
||||
|
||||
if(RangeInCentimeters > 0) distanceBackup = RangeInCentimeters;
|
||||
if (RangeInCentimeters > 0) distanceBackup = RangeInCentimeters;
|
||||
else RangeInCentimeters = distanceBackup;
|
||||
|
||||
basic.pause(50);
|
||||
@ -468,8 +450,7 @@ namespace grove {
|
||||
* @param pin signal pin of ultrasonic ranger module
|
||||
*/
|
||||
//% blockId=grove_ultrasonic_inches block="Ultrasonic Sensor (in inch) at|%pin"
|
||||
export function measureInInches(pin: DigitalPin): number
|
||||
{
|
||||
export function measureInInches(pin: DigitalPin): number {
|
||||
let duration = 0;
|
||||
let RangeInInches = 0;
|
||||
|
||||
@ -482,7 +463,7 @@ namespace grove {
|
||||
|
||||
RangeInInches = duration * 153 / 74 / 2 / 100;
|
||||
|
||||
if(RangeInInches > 0) distanceBackup = RangeInInches;
|
||||
if (RangeInInches > 0) distanceBackup = RangeInInches;
|
||||
else RangeInInches = distanceBackup;
|
||||
|
||||
basic.pause(50);
|
||||
@ -496,8 +477,7 @@ namespace grove {
|
||||
* @param dataPin value of data pin number
|
||||
*/
|
||||
//% blockId=grove_tm1637_create block="4-Digit Display at|%clkPin|and|%dataPin"
|
||||
export function createDisplay(clkPin: DigitalPin, dataPin: DigitalPin): TM1637
|
||||
{
|
||||
export function createDisplay(clkPin: DigitalPin, dataPin: DigitalPin): TM1637 {
|
||||
let display = new TM1637();
|
||||
|
||||
display.buf = pins.createBuffer(4);
|
||||
@ -549,7 +529,7 @@ namespace grove {
|
||||
control.onEvent(gestureEventId, gesture, handler);
|
||||
paj7620.init();
|
||||
control.inBackground(() => {
|
||||
while(true) {
|
||||
while (true) {
|
||||
const gesture = paj7620.read();
|
||||
if (gesture != lastGesture) {
|
||||
lastGesture = gesture;
|
||||
@ -572,7 +552,7 @@ namespace grove {
|
||||
export function onJoystick(key: GroveJoystickKey, xpin: AnalogPin, ypin: AnalogPin, handler: () => void) {
|
||||
control.onEvent(joystickEventID, key, handler);
|
||||
control.inBackground(() => {
|
||||
while(true) {
|
||||
while (true) {
|
||||
const key = joystick.read(xpin, ypin);
|
||||
if (key != lastJoystick) {
|
||||
lastJoystick = key;
|
||||
|
Loading…
Reference in New Issue
Block a user