Vai al contenuto

primo approccio arduino


nicolini2000

Messaggi raccomandati

ho acquistato arduino mega ma non so da dove cominciare. Ho caricato alcuni

esempi e ho capito il loro funzionamento. ho provato a modificare il progetto blink, volendo realizzare l'uscita 13 con un tempo on-off e l'uscita 12 con un secondo tempo on-off ma il risultato non e quello voluto. i due led al variare dei tempi vorrei che lampeggiassero indipendentemente fra loro. chi puo aiutarmi vi posto lo sketch

/* far lampeggiare 2 led */

 

int led1 = 13;

int led2 = 12;

void setup() {

 

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

}

 

void loop() {

digitalWrite(led1, HIGH);

delay(1000);

digitalWrite(led1, LOW);

delay(1000);

 

digitalWrite(led2, HIGH);

delay(1000);

digitalWrite(led2, LOW);

delay(1000);

}

Link al commento
Condividi su altri siti

Ciao :)

Sono nuovo nel forum ma ti posto un mio vecchio codice a 5 Led che facevano la "ola" con arduino 1 + ethernet shield

Se rielabori il codice , togliendo quello in eccesso relativo alla ethernet shield , ti tornerà utile credo!

A me per lo meno funzionava e ci ho messo una vita a scriverlo!

 

/*Sketch a cura di Furma94 
Esame di Stato 2013-2014
Inizio Progettazione 24/07/13
*/


#include <String.h>    //Libreria Stringhe (Variabile)
#include <SPI.h>       //Libreria effettiva utilizzo dei Pin LOW HIGH
#include <Ethernet.h>  //Libreria che inializza l'apertura della Shield applicata sull'Arduino

byte mac_adress[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  //Stringa Mac Adress
byte indirizzo_ip[] = { 192, 168, 0, 8};                        // indirizzo IP del server (Statico assegnato da qua)
byte gateway[] = { 192, 168, 0, 1 };                  // indirizzo ip del router
byte subnet[] = { 255, 255, 255, 0 };                 //subnet mask
EthernetServer server(80); //server port
int ledPin2 = 2; // Dichiarazione variabile led 
int ledPin3 = 3; // Dichiarazione variabile led 
int ledPin5 = 5; // Dichiarazione variabile led 
int ledPin6 = 6; // Dichiarazione variabile led 
int ledPin7 = 7; // Dichiarazione variabile led 
int ledPin8 = 8; // Dichiarazione variabile led 
int ledPin9 = 9; // Dichiarazione variabile led 
String readString; //string
boolean LEDON = false; //LED Flag

void setup(){
Ethernet.begin(mac_adress, indirizzo_ip, gateway, subnet);  // Inializzazione shield con parametri di connessione in ordine 1)Mac 2)Ip 3)Gate 4)SubMask
pinMode(ledPin2, OUTPUT);  //Associazione In/Out al pin da associare
pinMode(ledPin3, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
Serial.begin(9600);
}   
void loop(){
EthernetClient client = server.available();
if (client) {
 boolean currentLineIsBlank = true;
 while (client.connected()) {
   if (client.available()) {
     char c = client.read();
       readString.concat(c); //store characters to string
     //if HTTP request has ended
     if (c == '\n' && currentLineIsBlank) {
        Serial.print(readString);
       if(readString.indexOf("L=1") > 0) {//lets check if LED should be lighted
         //led has to be turned ON
         digitalWrite(ledPin2, HIGH); // set the LED on
         digitalWrite(ledPin9, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin2, LOW); // set the LED on
         digitalWrite(ledPin9, LOW); // set the LED on  
         digitalWrite(ledPin3, HIGH); // set the LED on
         digitalWrite(ledPin8, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin3, LOW); // set the LED on
         digitalWrite(ledPin8, LOW); // set the LED on  
         digitalWrite(ledPin5, HIGH); // set the LED on
         digitalWrite(ledPin7, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin7, LOW); // set the LED on
         digitalWrite(ledPin5, LOW); // set the LED on  
         digitalWrite(ledPin6, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin6, LOW); // set the LED on  
         digitalWrite(ledPin5, HIGH); // set the LED on
         digitalWrite(ledPin7, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin7, LOW); // set the LED on
         digitalWrite(ledPin5, LOW); // set the LED on  
         digitalWrite(ledPin3, HIGH); // set the LED on
         digitalWrite(ledPin8, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin3, LOW); // set the LED on
         digitalWrite(ledPin8, LOW); // set the LED on 
         digitalWrite(ledPin2, HIGH); // set the LED on
         digitalWrite(ledPin9, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin2, LOW); // set the LED on
         digitalWrite(ledPin9, LOW); // set the LED on 
       digitalWrite(ledPin2, HIGH); // set the LED on
         digitalWrite(ledPin9, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin2, LOW); // set the LED on
         digitalWrite(ledPin9, LOW); // set the LED on  
         digitalWrite(ledPin3, HIGH); // set the LED on
         digitalWrite(ledPin8, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin3, LOW); // set the LED on
         digitalWrite(ledPin8, LOW); // set the LED on  
         digitalWrite(ledPin5, HIGH); // set the LED on
         digitalWrite(ledPin7, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin7, LOW); // set the LED on
         digitalWrite(ledPin5, LOW); // set the LED on  
         digitalWrite(ledPin6, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin6, LOW); // set the LED on  
         digitalWrite(ledPin5, HIGH); // set the LED on
         digitalWrite(ledPin7, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin7, LOW); // set the LED on
         digitalWrite(ledPin5, LOW); // set the LED on  
         digitalWrite(ledPin3, HIGH); // set the LED on
         digitalWrite(ledPin8, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin3, LOW); // set the LED on
         digitalWrite(ledPin8, LOW); // set the LED on 
         digitalWrite(ledPin2, HIGH); // set the LED on
         digitalWrite(ledPin9, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin2, LOW); // set the LED on
         digitalWrite(ledPin9, LOW); // set the LED on   
       digitalWrite(ledPin2, HIGH); // set the LED on
         digitalWrite(ledPin9, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin2, LOW); // set the LED on
         digitalWrite(ledPin9, LOW); // set the LED on  
         digitalWrite(ledPin3, HIGH); // set the LED on
         digitalWrite(ledPin8, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin3, LOW); // set the LED on
         digitalWrite(ledPin8, LOW); // set the LED on  
         digitalWrite(ledPin5, HIGH); // set the LED on
         digitalWrite(ledPin7, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin7, LOW); // set the LED on
         digitalWrite(ledPin5, LOW); // set the LED on  
         digitalWrite(ledPin6, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin6, LOW); // set the LED on  
         digitalWrite(ledPin5, HIGH); // set the LED on
         digitalWrite(ledPin7, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin7, LOW); // set the LED on
         digitalWrite(ledPin5, LOW); // set the LED on  
         digitalWrite(ledPin3, HIGH); // set the LED on
         digitalWrite(ledPin8, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin3, LOW); // set the LED on
         digitalWrite(ledPin8, LOW); // set the LED on 
         digitalWrite(ledPin2, HIGH); // set the LED on
         digitalWrite(ledPin9, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin2, LOW); // set the LED on
         digitalWrite(ledPin9, LOW); // set the LED on   
       digitalWrite(ledPin2, HIGH); // set the LED on
         digitalWrite(ledPin9, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin2, LOW); // set the LED on
         digitalWrite(ledPin9, LOW); // set the LED on  
         digitalWrite(ledPin3, HIGH); // set the LED on
         digitalWrite(ledPin8, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin3, LOW); // set the LED on
         digitalWrite(ledPin8, LOW); // set the LED on  
         digitalWrite(ledPin5, HIGH); // set the LED on
         digitalWrite(ledPin7, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin7, LOW); // set the LED on
         digitalWrite(ledPin5, LOW); // set the LED on  
         digitalWrite(ledPin6, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin6, LOW); // set the LED on  
         digitalWrite(ledPin5, HIGH); // set the LED on
         digitalWrite(ledPin7, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin7, LOW); // set the LED on
         digitalWrite(ledPin5, LOW); // set the LED on  
         digitalWrite(ledPin3, HIGH); // set the LED on
         digitalWrite(ledPin8, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin3, LOW); // set the LED on
         digitalWrite(ledPin8, LOW); // set the LED on 
         digitalWrite(ledPin2, HIGH); // set the LED on
         digitalWrite(ledPin9, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin2, LOW); // set the LED on
         digitalWrite(ledPin9, LOW); // set the LED on   
       digitalWrite(ledPin2, HIGH); // set the LED on
         digitalWrite(ledPin9, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin2, LOW); // set the LED on
         digitalWrite(ledPin9, LOW); // set the LED on  
         digitalWrite(ledPin3, HIGH); // set the LED on
         digitalWrite(ledPin8, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin3, LOW); // set the LED on
         digitalWrite(ledPin8, LOW); // set the LED on  
         digitalWrite(ledPin5, HIGH); // set the LED on
         digitalWrite(ledPin7, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin7, LOW); // set the LED on
         digitalWrite(ledPin5, LOW); // set the LED on  
         digitalWrite(ledPin6, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin6, LOW); // set the LED on  
         digitalWrite(ledPin5, HIGH); // set the LED on
         digitalWrite(ledPin7, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin7, LOW); // set the LED on
         digitalWrite(ledPin5, LOW); // set the LED on  
         digitalWrite(ledPin3, HIGH); // set the LED on
         digitalWrite(ledPin8, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin3, LOW); // set the LED on
         digitalWrite(ledPin8, LOW); // set the LED on 
         digitalWrite(ledPin2, HIGH); // set the LED on
         digitalWrite(ledPin9, HIGH); // set the LED on
           delay(250);  
         digitalWrite(ledPin2, LOW); // set the LED on
         digitalWrite(ledPin9, LOW); // set the LED on     
         LEDON = true;
         }else{
         //led has to be turned OFF
         digitalWrite(ledPin2, LOW); // set the LED OFF
         digitalWrite(ledPin3, LOW); // set the LED OFF
         digitalWrite(ledPin5, LOW); // set the LED OFF
         digitalWrite(ledPin6, LOW); // set the LED OFF
         digitalWrite(ledPin7, LOW); // set the LED OFF
         digitalWrite(ledPin8, LOW); // set the LED OFF
         digitalWrite(ledPin9, LOW); // set the LED OFF
         LEDON = false;
       }
       // now output HTML data starting with standart header
       client.println("HTTP/1.1 200 OK");
       client.println("Content-Type: text/html");
       client.println();
       client.print("<html><head><title>Tesi d'Esame a cura di Raffaele Formaggi e Spirandelli Alessio</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>");
       //send first heading
       client.println("<h1>LED CONTROL by internet connection</h1>");
       client.println("<hr />");
       client.println("<h1>LED control</h1>");
       //printing LED status
       client.print("<span>LED status: </span>");
         if (LEDON) {
          client.println("<span style='color:green'>ON</span>");
           } 
           else
           {
          client.println("<span style='color:grey'>OFF</span>");
         }
       client.print("<h2><a href='/?L=1'>ACCENDI</a> | <a href='/?L=0'>SPEGNI</a></h2>");
       client.println("</body></html>");
       readString="";
       client.stop();

       } //if c == /n 
   } // if client available
 } // while client connesso
} // if client
} //loop

Link al commento
Condividi su altri siti

Crea un account o accedi per lasciare un commento

Devi essere un membro per lasciare un commento

Crea un account

Iscriviti per un nuovo account nella nostra community. È facile!

Registra un nuovo account

Accedi

Sei già registrato? Accedi qui.

Accedi Ora

Giochi in Uscita



  • Community Hive Community Hive

    Community Hive allows you to follow your favorite communities all in one place.

    Follow on Community Hive
  • Utenti

    Non ci sono membri da mostrare

×
×
  • Crea Nuovo...