summaryrefslogtreecommitdiff
path: root/1-scala-led-potenziometro.ino
diff options
context:
space:
mode:
authorLuca Tringali <tringalinvent@libero.it>2019-03-11 23:02:50 +0100
committerLuca Tringali <tringalinvent@libero.it>2019-03-11 23:02:50 +0100
commit091f0c084f44ba6ce1656cdc73ab034abc881620 (patch)
treeef68cdf5fb2b033a42d2c94bbc656b047deb17c0 /1-scala-led-potenziometro.ino
parent299ee1066f15506da34beeba6e90a44891780734 (diff)
Rinomina fileHEADmaster
Diffstat (limited to '1-scala-led-potenziometro.ino')
-rw-r--r--1-scala-led-potenziometro.ino55
1 files changed, 55 insertions, 0 deletions
diff --git a/1-scala-led-potenziometro.ino b/1-scala-led-potenziometro.ino
new file mode 100644
index 0000000..62a2d45
--- /dev/null
+++ b/1-scala-led-potenziometro.ino
@@ -0,0 +1,55 @@
+int potPin = 2; // pin analogico potenziometro
+
+int ledPin1 = 3; //pin dei led
+int ledPin2 = 4;
+int ledPin3 = 5;
+int ledPin4 = 6;
+int ledPin5 = 7;
+
+
+void setup() {
+ pinMode(ledPin1, OUTPUT); // dichiaro i ledPin come OUTPUT
+ pinMode(ledPin2, OUTPUT);
+ pinMode(ledPin3, OUTPUT);
+ pinMode(ledPin4, OUTPUT);
+ pinMode(ledPin5, OUTPUT);
+}
+
+void loop() {
+ int val = 0;
+ val = analogRead(potPin); //inserisco in val il valore del potenziometro
+ int mappedval = 0;
+ mappedval = map(val, 0, 1023, 0, 5); //mappo il valore dall'intervallo 0-1023 a 0-5
+
+ if (mappedval>0) {
+ digitalWrite(ledPin1, HIGH);
+ } else {
+ digitalWrite(ledPin1, LOW);
+ }
+
+ if (mappedval>1) {
+ digitalWrite(ledPin2, HIGH);
+ } else {
+ digitalWrite(ledPin2, LOW);
+ }
+
+ if (mappedval>2) {
+ digitalWrite(ledPin3, HIGH);
+ } else {
+ digitalWrite(ledPin3, LOW);
+ }
+
+ if (mappedval>3) {
+ digitalWrite(ledPin4, HIGH);
+ } else {
+ digitalWrite(ledPin4, LOW);
+ }
+
+ if (mappedval>4) {
+ digitalWrite(ledPin5, HIGH);
+ } else {
+ digitalWrite(ledPin5, LOW);
+ }
+
+}
+