The cart is empty

Valutazione attuale: 0 / 5

Stella inattivaStella inattivaStella inattivaStella inattivaStella inattiva




.



#include <Ethernet.h>
#include <SPI.h>
boolean reading = false;

////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////
  byte ip[] = { 192, 168, 1, 150 };   //ip address to assign the arduino
  byte gateway[] = { 192, 168, 1, 1 }; //ip address of the gatewa or router

  //Rarly need to change this
  byte subnet[] = { 255, 255, 255, 0 };

  // if need to change the MAC address (Very Rare)
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

  Server server = Server(80); //port 80
////////////////////////////////////////////////////////////////////////

void setup(){
  //Pins 10,11,12 & 13 are used by the ethernet shield

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);

  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
}

void loop(){

  // listen for incoming clients, and process qequest.
  checkForClient();

}

void checkForClient(){

  Client client = server.available();

  if (client) {

    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    boolean sentHeader = false;

    while (client.connected()) {
      if (client.available()) {

        if(!sentHeader){
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          sentHeader = true;
        }

        char c = client.read();

        if(reading && c == ' ') reading = false;
        if(c == '?') reading = true; //found the ?, begin reading the info

        if(reading){
          Serial.print(c);

           switch (c) {
            case '2':
              //add code here to trigger on 2
              triggerPin(2, client);
              break;
            case '3':
            //add code here to trigger on 3
              triggerPin(3, client);
              break;
            case '4':
            //add code here to trigger on 4
              triggerPin(4, client);
              break;
            case '5':
            //add code here to trigger on 5
              triggerPin(5, client);
              break;
            case '6':
            //add code here to trigger on 6
              triggerPin(6, client);
              break;
            case '7':
            //add code here to trigger on 7
              triggerPin(7, client);
              break;
            case '8':
            //add code here to trigger on 8
              triggerPin(8, client);
              break;
            case '9':
            //add code here to trigger on 9
              triggerPin(9, client);
              break;
          }

        }

        if (c == '\n' && currentLineIsBlank)  break;

        if (c == '\n') {
          currentLineIsBlank = true;
        }else if (c != '\r') {
          currentLineIsBlank = false;
        }

      }
    }

    delay(1); // give the web browser time to receive the data
    client.stop(); // close the connection:

  }

}

void triggerPin(int pin, Client client){
//blink a pin - Client needed just for HTML output purposes. 
  client.print("Turning on pin ");
  client.println(pin);
  client.print("<br>");

  digitalWrite(pin, HIGH);
  delay(25);
  digitalWrite(pin, LOW);
  delay(25);
}

Valutazione attuale: 0 / 5

Stella inattivaStella inattivaStella inattivaStella inattivaStella inattiva


In costruzione
..................

{ddtoc_break title=Crepuscolare
}

/* Simple test of the functionality of the photo resistor

Connect the photoresistor one leg to pin 0, and pin to +5V
Connect a resistor (around 10k is a good value, higher
values gives higher readings) from pin 0 to GND. (see appendix of arduino notebook page 37 for schematics).

----------------------------------------------------

PhotoR 10K
+5 o---/\/\/--.--/\/\/---o GND
|
Pin 0 o-----------

----------------------------------------------------
*/

int lightPin = 0; //define a pin for Photo resistor
int ledPin=12; //define a pin for LED
char Str1[ ] = "Acceso";
char Str2[ ] = "Spento";

void setup()
{
Serial.begin(9600);
pinMode( ledPin, OUTPUT );
}

void loop()
{
if ((analogRead(lightPin)) < 500)
{
Serial.println("BUIO");// action A
}
else
{
Serial.println("LUCE");// action B
}
analogWrite(ledPin, analogRead(lightPin)/2); //send the value to the ledPin. Depending on value of resistor
//you have to divide the value. for example,
//with a 10k resistor divide the value by 2, for 100k resistor divide by 4.
delay(1000); //short delay for faster response to light.
}

{ddtoc_break title=SRF05}

//Code for using SRF05 with Arduino and Wiring
//SRF05 works in default mode-using same pin for pulse
// and echo
// The Mode pin of SRF05 is connected to Ground

int SRF05pin = 8; //connect to digital pin 8
unsigned long ultrasoundDuration;

void setup()
{
Serial.begin(9600);
}

void loop()
{
pinMode(SRF05pin, OUTPUT); //pin is output
digitalWrite(SRF05pin, LOW);
delayMicroseconds(2);
digitalWrite(SRF05pin, HIGH);
delayMicroseconds(10);
digitalWrite(SRF05pin, LOW);

pinMode(SRF05pin, INPUT); // pin is now input
// wait for a high pulse
ultrasoundDuration = pulseIn(SRF05pin, HIGH);
// get results
Serial.print(ultrasoundDuration);
Serial.print(ultrasoundDuration/148, DEC); //divide with 58 and you get cm
Serial.print(" inches");
Serial.println();
delay(100);
}


{ddtoc_break title=Led}

{ddtoc_break title=Relè}

Valutazione attuale: 0 / 5

Stella inattivaStella inattivaStella inattivaStella inattivaStella inattiva

Arduino progetto
Le mie grandi passioni: Pesca Spinning - Elettronica

articolo in costruzione
LCD 16x4

Un bug nella libreria LiquidCrystal non permette di allineare il testo nella posizione voluta, nel mio caso con un lcd 16x4 la terza e quarta riga partivano dalla colonna quattro.
Il perchè di questo è spiegato qui.
Ecco la soluzione:
aprire il file LiquidCrystal.cpp, con Notepad Plus questa la schermata ed il numero di riga:

alt

Seguendo il link indicato sopra si evincono le modifiche da fare, nel mio caso:

alt


che diventa:

alt
 

Ora funziona perfettamente:

alt

{ddtoc_break title=Code pde}


 
// Il codice contiene anche operazioni sulle stringhe.
// Aggiungere al valore letto na stringa personalizata
 

#include <LiquidCrystal.h>

// Connections:
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
// LCD pins d0, d1, d2, d3 to Arduino pins 9, 8, 7, 6
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

int backLight = 13;    // pin 13 controllo backlight
int photoresistor = 2; //fotoresistenza analogico pin 2
int forcesensor=1; //sensore di forza analogico pin 1

String valore_1, valore_2;


void setup()
{
  valore_1 = String("Sensor ");//sensore luce
  valore_2 = String("value");
  lcd.println("\n\nAppending to a string:");
 
  pinMode(backLight, OUTPUT);
  digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(16,4);              // modificare LiquidCrystal.cpp secondo il display
  lcd.clear();                  // pulisce il display
  lcd.setCursor(0,0);           // prima riga, prima colonna
  lcd.print("Guido Zaccardini");    //
  lcd.setCursor(0,1);           // seconda riga
  lcd.print("minimamente.it");
 
 
}

void loop()
{
  valore_2=("Forza : ");
  valore_2 += analogRead(forcesensor);
 
  valore_1=("luce : ");
  valore_1 += analogRead(photoresistor);
 
   lcd.setCursor(0,2);         // terza riga
   lcd.print(valore_1);
 
   lcd.setCursor(0,3);         // quarta riga
   lcd.print(valore_2);
 
  delay(500);
}

{ddtoc_break title=Connessioni}

alt

under contruction


MINIMAMENTE

Sassifraghe ombrose le nostre anime, avvolte in un involucro alimentare

 

 

Latest News

18 Giugno 2016
18 Giugno 2016