From 091f0c084f44ba6ce1656cdc73ab034abc881620 Mon Sep 17 00:00:00 2001 From: Luca Tringali Date: Mon, 11 Mar 2019 23:02:50 +0100 Subject: Rinomina file --- 1-scala-led-potenziometro.ino | 55 ++++++++++++++++++++ 2-temperatura-lm35.ino | 15 ++++++ 3-dissolvenza-led-distanza-ultrasuoni.ino | 41 +++++++++++++++ 4-ethernet-servomotore.ino | 84 +++++++++++++++++++++++++++++++ dissolvenza-led-distanza-ultrasuoni.ino | 41 --------------- ethernet-servomotore.ino | 84 ------------------------------- scala-led-potenziometro.ino | 55 -------------------- temperatura-lm35.ino | 15 ------ 8 files changed, 195 insertions(+), 195 deletions(-) create mode 100644 1-scala-led-potenziometro.ino create mode 100644 2-temperatura-lm35.ino create mode 100644 3-dissolvenza-led-distanza-ultrasuoni.ino create mode 100644 4-ethernet-servomotore.ino delete mode 100644 dissolvenza-led-distanza-ultrasuoni.ino delete mode 100644 ethernet-servomotore.ino delete mode 100644 scala-led-potenziometro.ino delete mode 100644 temperatura-lm35.ino 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); + } + +} + diff --git a/2-temperatura-lm35.ino b/2-temperatura-lm35.ino new file mode 100644 index 0000000..a75cb28 --- /dev/null +++ b/2-temperatura-lm35.ino @@ -0,0 +1,15 @@ +int pin = 1; +double temp = 0.0; + +void setup(){ + Serial.begin(9600); +} + +void loop(){ + temp = analogRead(pin)*(500/1023); + Serial.print ("Stanza 1: "); + Serial.print (temp); + Serial.print ("° C"); + Serial.println(); + delay(1000); +} diff --git a/3-dissolvenza-led-distanza-ultrasuoni.ino b/3-dissolvenza-led-distanza-ultrasuoni.ino new file mode 100644 index 0000000..a7be908 --- /dev/null +++ b/3-dissolvenza-led-distanza-ultrasuoni.ino @@ -0,0 +1,41 @@ +//HC RS04 Sensore ultrasuoni +const int triggerPort = 9; +const int echoPort = 10; +const int led = 3; + +void setup() { + +pinMode(triggerPort, OUTPUT); +pinMode(echoPort, INPUT); +pinMode(led, OUTPUT); +Serial.begin(9600); +} + +void loop() { + + +digitalWrite( triggerPort, LOW ); +//invia un impulso di 10microsec su trigger +digitalWrite( triggerPort, HIGH ); +delayMicroseconds( 10 ); +digitalWrite( triggerPort, LOW ); + +long durata = pulseIn( echoPort, HIGH ); + +long distanza = 0.034 * durata / 2; + +Serial.print("distanza: "); + +//durata in millisecondi +if( durata > 38000 ){ +Serial.println("Fuori portata "); +} +else{ +Serial.print(distanza); +Serial.println(" cm"); +int fadeValue = map(durata, 0, 38000, 0, 255) +analogWrite(led, fadeValue); +} + +delay(1000); +} diff --git a/4-ethernet-servomotore.ino b/4-ethernet-servomotore.ino new file mode 100644 index 0000000..a4045e3 --- /dev/null +++ b/4-ethernet-servomotore.ino @@ -0,0 +1,84 @@ +#include +#include + + +#include + +Servo myservo; // create servo object to control a servo +int servopin = 3; + +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address + +char serverName[] = "codice-sorgente.it"; +char serverPage[] = "/UTCTime.php?zone=Europe/Rome"; +EthernetClient client; + +////////////////////// + +void setup(){ + + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // no point in carrying on, so do nothing forevermore: + while(true); + } + + Serial.begin(9600); + myservo.attach(servopin); + Serial.println("Init"); +} + +void loop(){ + delay(3000); + sendGET(); +} + +////////////////////////// + +void sendGET() //client function to send/receive GET request data. +{ + if (client.connect(serverName, 80)) { //starts client connection, checks for connection + Serial.println("connected"); +// client.println("GET /ioprogrammo/UTCTime.php HTTP/1.0"); //download text + client.print("GET "); + client.print(serverPage); + client.println(" HTTP/1.0"); + client.print("Host: "); + client.println(serverName); + client.println(); //end of get request + } + else { + Serial.println("connection failed"); //error message if no client connect + Serial.println(); + return; + } + +String response = ""; + while(client.connected() && !client.available()) delay(1); //waits for data + while (client.connected() || client.available()) { //connected or data available + char c = client.read(); //gets byte from ethernet buffer + response += c; + } + + Serial.println(response); + int da = response.indexOf("<")+1; + int a = response.indexOf(">"); + String pageValue = response.substring(da,a); + + da = pageValue.indexOf(" ")+1; + a = pageValue.indexOf(":",da); + String hour = pageValue.substring(da,a); + int ora = hour.toInt(); + int rotazione = map(ora, 0, 23, 0, 180); //può essere 90 invece di 180 + Serial.print("Writing this value to servo: "); + Serial.println(rotazione); + myservo.write(rotazione); + + Serial.println(); + Serial.println("disconnecting."); + Serial.println("=================="); + Serial.println(); + client.stop(); //stop client + +} + diff --git a/dissolvenza-led-distanza-ultrasuoni.ino b/dissolvenza-led-distanza-ultrasuoni.ino deleted file mode 100644 index a7be908..0000000 --- a/dissolvenza-led-distanza-ultrasuoni.ino +++ /dev/null @@ -1,41 +0,0 @@ -//HC RS04 Sensore ultrasuoni -const int triggerPort = 9; -const int echoPort = 10; -const int led = 3; - -void setup() { - -pinMode(triggerPort, OUTPUT); -pinMode(echoPort, INPUT); -pinMode(led, OUTPUT); -Serial.begin(9600); -} - -void loop() { - - -digitalWrite( triggerPort, LOW ); -//invia un impulso di 10microsec su trigger -digitalWrite( triggerPort, HIGH ); -delayMicroseconds( 10 ); -digitalWrite( triggerPort, LOW ); - -long durata = pulseIn( echoPort, HIGH ); - -long distanza = 0.034 * durata / 2; - -Serial.print("distanza: "); - -//durata in millisecondi -if( durata > 38000 ){ -Serial.println("Fuori portata "); -} -else{ -Serial.print(distanza); -Serial.println(" cm"); -int fadeValue = map(durata, 0, 38000, 0, 255) -analogWrite(led, fadeValue); -} - -delay(1000); -} diff --git a/ethernet-servomotore.ino b/ethernet-servomotore.ino deleted file mode 100644 index a4045e3..0000000 --- a/ethernet-servomotore.ino +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include - - -#include - -Servo myservo; // create servo object to control a servo -int servopin = 3; - -byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address - -char serverName[] = "codice-sorgente.it"; -char serverPage[] = "/UTCTime.php?zone=Europe/Rome"; -EthernetClient client; - -////////////////////// - -void setup(){ - - if (Ethernet.begin(mac) == 0) { - Serial.println("Failed to configure Ethernet using DHCP"); - // no point in carrying on, so do nothing forevermore: - while(true); - } - - Serial.begin(9600); - myservo.attach(servopin); - Serial.println("Init"); -} - -void loop(){ - delay(3000); - sendGET(); -} - -////////////////////////// - -void sendGET() //client function to send/receive GET request data. -{ - if (client.connect(serverName, 80)) { //starts client connection, checks for connection - Serial.println("connected"); -// client.println("GET /ioprogrammo/UTCTime.php HTTP/1.0"); //download text - client.print("GET "); - client.print(serverPage); - client.println(" HTTP/1.0"); - client.print("Host: "); - client.println(serverName); - client.println(); //end of get request - } - else { - Serial.println("connection failed"); //error message if no client connect - Serial.println(); - return; - } - -String response = ""; - while(client.connected() && !client.available()) delay(1); //waits for data - while (client.connected() || client.available()) { //connected or data available - char c = client.read(); //gets byte from ethernet buffer - response += c; - } - - Serial.println(response); - int da = response.indexOf("<")+1; - int a = response.indexOf(">"); - String pageValue = response.substring(da,a); - - da = pageValue.indexOf(" ")+1; - a = pageValue.indexOf(":",da); - String hour = pageValue.substring(da,a); - int ora = hour.toInt(); - int rotazione = map(ora, 0, 23, 0, 180); //può essere 90 invece di 180 - Serial.print("Writing this value to servo: "); - Serial.println(rotazione); - myservo.write(rotazione); - - Serial.println(); - Serial.println("disconnecting."); - Serial.println("=================="); - Serial.println(); - client.stop(); //stop client - -} - diff --git a/scala-led-potenziometro.ino b/scala-led-potenziometro.ino deleted file mode 100644 index 62a2d45..0000000 --- a/scala-led-potenziometro.ino +++ /dev/null @@ -1,55 +0,0 @@ -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); - } - -} - diff --git a/temperatura-lm35.ino b/temperatura-lm35.ino deleted file mode 100644 index a75cb28..0000000 --- a/temperatura-lm35.ino +++ /dev/null @@ -1,15 +0,0 @@ -int pin = 1; -double temp = 0.0; - -void setup(){ - Serial.begin(9600); -} - -void loop(){ - temp = analogRead(pin)*(500/1023); - Serial.print ("Stanza 1: "); - Serial.print (temp); - Serial.print ("° C"); - Serial.println(); - delay(1000); -} -- cgit v1.1