Last active
November 28, 2016 22:55
-
-
Save samelhusseini/c986a749d414f7b54e996b72908ec418 to your computer and use it in GitHub Desktop.
Rotary_Encoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let Min_X = 1; | |
let Max_X = 15; | |
let a = 0 | |
let b = 0 | |
let x = 5 | |
let lastA = pins.digitalReadPin(DigitalPin.P5); | |
basic.forever(() => { | |
a = pins.digitalReadPin(DigitalPin.P5); | |
b = pins.digitalReadPin(DigitalPin.P11) | |
if ((a != lastA) && (a == 0)) { | |
// Knob Rotated l when aVal changes, BUT use only if aVal is LOW. | |
if (b == 0) { | |
x++; | |
} else { | |
x--; | |
} | |
x = Math.max(Min_X, Math.min(x, Max_X)) | |
} | |
// keep x from 0 to 9 | |
lastA = a | |
}) | |
basic.forever(() => { | |
led.plotBarGraph(x, Max_X) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Rotary_Encoder", | |
"version": "0.0.0", | |
"description": "Rotary Encoder Project", | |
"license": "MIT", | |
"dependencies": { | |
"core": "*", | |
"radio": "*" | |
}, | |
"files": [ | |
"main.ts" | |
], | |
"public": true, | |
"publicGist": true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment