-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathProject 25.js
94 lines (89 loc) · 1.98 KB
/
Project 25.js
1
var b = require('bonescript');var ledPin0 = "P9_11";var ledPin1 = "P9_13";var ledPin2 = "P9_15";var ledPin3 = "P9_17";var ledPin4 = "P9_21";var ledPin5 = "P9_22";var ledPin6 = "P9_12";var ledPin7 = "P9_14";var ledPin8 = "P9_16";var ledPin9 = "P9_18";b.pinMode(ledPin0, b.OUTPUT);b.pinMode(ledPin1, b.OUTPUT);b.pinMode(ledPin2, b.OUTPUT);b.pinMode(ledPin3, b.OUTPUT);b.pinMode(ledPin4, b.OUTPUT);b.pinMode(ledPin5, b.OUTPUT);b.pinMode(ledPin6, b.OUTPUT);b.pinMode(ledPin7, b.OUTPUT);b.pinMode(ledPin8, b.OUTPUT);b.pinMode(ledPin9, b.OUTPUT);var inputPin = "P9_40";loop()function loop() { var value = b.analogRead(inputPin); console.log(value*1.8); setTimeout(loop, 250); voltage = value*1.8; if (voltage > 0.4){ b.digitalWrite(ledPin9, b.HIGH); } else { b.digitalWrite(ledPin9, b.LOW); } if (voltage > 0.5){ b.digitalWrite(ledPin8, b.HIGH); } else { b.digitalWrite(ledPin8, b.LOW); } if (voltage > 0.6){ b.digitalWrite(ledPin7, b.HIGH); } else { b.digitalWrite(ledPin7, b.LOW); } if (voltage > 0.7){ b.digitalWrite(ledPin6, b.HIGH); } else { b.digitalWrite(ledPin6, b.LOW); } if (voltage > 0.8){ b.digitalWrite(ledPin5, b.HIGH); } else { b.digitalWrite(ledPin5, b.LOW); } if (voltage > 0.9){ b.digitalWrite(ledPin4, b.HIGH); } else { b.digitalWrite(ledPin4, b.LOW); } if (voltage > 1){ b.digitalWrite(ledPin3, b.HIGH); } else { b.digitalWrite(ledPin3, b.LOW); } if (voltage > 1.1){ b.digitalWrite(ledPin2, b.HIGH); } else { b.digitalWrite(ledPin2, b.LOW); } if (voltage > 1.2){ b.digitalWrite(ledPin1, b.HIGH); } else { b.digitalWrite(ledPin1, b.LOW); } if (voltage > 1.3){ b.digitalWrite(ledPin0, b.HIGH); } else { b.digitalWrite(ledPin0, b.LOW); }}