ghi-electronics / due-console

A console interface to work with DUE
https://console.duelink.com/
0 stars 0 forks source link

Demo Syntax Fix #42

Closed greg-norris closed 1 year ago

greg-norris commented 1 year ago

There are a couple of the DEMOS that have an issue.

1.) The Fade LED Demo code needs to be changed from "L" to 'L'.

@Loop For i=0 to 1000 Step 100 AWrite('L', i) Wait(100) Next For i=1000 to 0 Step -100 AWrite('L', i) Wait(100) Next Goto Loop

2.) The Read Button DEMO also has a similar issue. The "A" should be 'A'.

BtnEnable('A', 1) @Loop x=BtnDown('A') If x=1 PrintLn("Button A") End Wait(200) Goto Loop

dudedigital commented 1 year ago

@greg-norris @gus-ghielec It's not a string that way, it's a string this way. Why is this a thing!?

greg-norris commented 1 year ago

The L is an enum created for the on-board LED pin. A & B are also enums created for the A & B button pins.

gus-ghielec commented 1 year ago

@dudedigital because web developers need to learn about ASCII vs strings and this is a very good spot to learn that.

'A' is ASCII A and it is a value (a number) "A" is a string of 2 bytes (usually) and has 'A' in the first element and null in the second element.

Also, "A" is a pointer to 2 element array. 'A' is a number not a pointer.

DUE will teach everyone proper coding.

greg-norris commented 1 year ago

for this to work properly in JSON, you will need to escape the single quote with backslash.

AWrite(\'L\', i)'

dudedigital commented 1 year ago

@gus-ghielec The average web developer isn't really concerned with low level stuff like those in hardware. It's two different worlds, and someone may not always be interested in both. I'm personally on the fence.

For me, I was in the wrong headspace. I wasn't thinking in terms of strongly-typed declarations. In this case, single quotes are treated as an ascii (char)acter. In a loosely typed language, 'A' would be a string. I wouldn't define one or the other as proper or improper coding.