Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/banjerr/busyornot
Another Arduino exercise, re-factored with Node
https://github.com/banjerr/busyornot
Last synced: 6 days ago
JSON representation
Another Arduino exercise, re-factored with Node
- Host: GitHub
- URL: https://github.com/banjerr/busyornot
- Owner: Banjerr
- Created: 2017-01-22T18:53:39.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-23T00:10:27.000Z (almost 8 years ago)
- Last Synced: 2024-11-14T18:54:48.926Z (2 months ago)
- Language: JavaScript
- Size: 29.4 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# busyOrNot?
Another Arduino exercise that I've re-factored to use Node js with the Johnny-Five library. Basically, the little dial (potentiometer) speaks to the servo to tell it what it's "angle" should be; the idea was to have the servo arm point to a specific "state", to let others know if the person was busy or not.
I think I might use this as the basis for a "bed time traffic light" for my daughter; with the addition of some photo-resistors to check how much light is coming in.
![pic!](https://github.com/Banjerr/busyOrNot/blob/master/busyOrNot.gif)
## original C/C++ Arduino code
```c
/**
* BUSY OR NOT?
* by Benjamin Redden
*/#include
Servo myServo;int const potPin = A0;
int potVal;
int angle;void setup() {
myServo.attach(9);Serial.begin(9600);
}void loop() {
potVal = analogRead(potPin);
Serial.print("potVal: ");
Serial.print(potVal);angle = map(potVal, 0, 1023, 0, 179);
Serial.print(", angle: ");
Serial.print(angle);myServo.write(angle);
delay(15);
}
```## refactored, Node JS (Johnny-Five) code
```javascript
'use strict'/**
* BUSY OR NOT?
* by Benjamin Redden
*/const five = require('johnny-five'),
board = new five.Board();board.on('ready', function() {
let myServo = new five.Servo(9),
potPin = new five.Sensor({
pin: "A0",
freq: 250
}),
potVal,
angle = five.Fn.map(potVal, 0, 1023, 0 ,179);// get the current reading
potPin.on('data', function(){
potVal = this.value;myServo.to(angle);
});
});
```