Skip to content

Instantly share code, notes, and snippets.

@samelhusseini
Last active November 28, 2016 22:55
Show Gist options
  • Save samelhusseini/c986a749d414f7b54e996b72908ec418 to your computer and use it in GitHub Desktop.
Save samelhusseini/c986a749d414f7b54e996b72908ec418 to your computer and use it in GitHub Desktop.
Rotary_Encoder
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)
})
{
"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