Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Turn on LED using ethernet shield web browser on: May 18, 2011, 09:09:23 pm
I was able to get the code to run using a delay, but I really need to use millis.

Any help would be appreciated.

Code:
#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <Udp.h>
/*
Simple Ethernet Test
        Arduino server outputs simple text to browser
The circuit:
* Arduino Duemilanove
        * Arduino Ethernet shield
        * Basic FTDI breakout 5V
        *LED connected to GND and digital pin 4 via resistor
        http://www.sciencprog.com/
        Created: 2009.11.18
        By Minde
        Modified: 2011.04.06
          1. Changed obsolete Wstring.h functions to String.h
          2. Changed includes to match Ethernet library.
          3. Fixed LED control
        By Minde
*/

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x20, 0x3C }; //physical mac address
byte ip[] = { 192, 168, 1, 200 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 };                   //subnet mask
Server server(80);                                      //server port
byte sampledata=50;            //some sample data - outputs 2 (ascii = 50 DEC)            
int ledPin = 4;  // LED pin
char link[]="http://www.scienceprog.com/"; //link data
String readString = String(30); //string for fetching data from address
boolean LEDON = false; //LED status flag
void setup(){
//start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 4 to output
  pinMode(ledPin, OUTPUT);  
//enable serial datada print  
  Serial.begin(9600);
}
void loop(){
// Create a client connection
Client client = server.available();
  if (client) {
    while (client.connected()) {
   if (client.available()) {
    char c = client.read();
     //read char by char HTTP request
    if (readString.length() < 100)
      {
        //store characters to string
        readString += c; //replaces readString.append(c);
      }  
        //output chars to serial port
        Serial.print(c);
        //if HTTP request has ended
        if (c == '\n') {
          //dirty skip of "GET /favicon.ico HTTP/1.1"
          if (readString.indexOf("?") <0)
          {
            //skip everything
          }
          else
          //lets check if LED should be lighted
        if(readString.indexOf("L=1") >0)//replaces if(readString.contains("L=1"))
           {
             //led has to be turned ON
             digitalWrite(ledPin, HIGH);    // set the LED on
             LEDON = true;
delay(3000);
LEDON = false;
digitalWrite(ledPin, LOW);
           }
          // now output HTML data starting with standart header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          //set background to yellow
          client.print("<body style=background-color:yellow>");
          //send first heading
          client.println("<font color='red'><h1>HTTP test routines</font></h1>");
          client.println("<hr />");
          client.println("<hr />");
          //output some sample data to browser
          client.println("<font color='blue' size='5'>Sample data: ");
          client.print(sampledata);//lets output some data
          client.println("<br />");//some space between lines
          client.println("<hr />");
          //drawing simple table
          client.println("<font color='green'>Simple table: ");
          client.println("<br />");
          client.println("<table border=1><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr>");
          client.println("<tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>");          
          client.println("<br />");
          client.println("<hr />");
          //printing some link
          client.println("<font color='blue' size='5'>Link: ");
          client.print("<a href=");
          client.print(link);
          client.println(">Visit Scienceprog!</a>");
          client.println("<br />");
          client.println("<hr />");
          //controlling led via checkbox
          client.println("<h1>LED control</h1>");
          //address will look like http://192.168.1.110/?L=1 when submited
          if (LEDON)
          client.println("<form method=get name=LED><input type=checkbox name=L value=1 CHECKED>LED<br><input type=submit value=submit></form>");
          else
          client.println("<form method=get name=LED><input type=checkbox name=L value=1>LED<br><input type=submit value=submit></form>");      
          client.println("<br />");
          //printing LED status
          client.print("<font size='5'>LED status: ");
          if (LEDON)
              client.println("<font color='green' size='5'>ON");
          else
              client.println("<font color='grey' size='5'>OFF");    
          client.println("<hr />");
          client.println("<hr />");
          client.println("</body></html>");
          //clearing string for next read
          readString="";
          //stopping client
          client.stop();
            }
          }
        }
      }
 }    





2  Using Arduino / Programming Questions / Turn on LED using ethernet shield web browser on: May 18, 2011, 08:01:56 pm
I want to turn on a LED using an ethernet shield on the web for like 5 seconds, then have it turn off automatically.

The code below is somewhat that I am looking for, but it just turns on the LED when button is pressed, and off when pressed. 

Code:
#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <Udp.h>
/*
Simple Ethernet Test
        Arduino server outputs simple text to browser
The circuit:
* Arduino Duemilanove
        * Arduino Ethernet shield
        * Basic FTDI breakout 5V
        *LED connected to GND and digital pin 4 via resistor
        http://www.sciencprog.com/
        Created: 2009.11.18
        By Minde
        Modified: 2011.04.06
          1. Changed obsolete Wstring.h functions to String.h
          2. Changed includes to match Ethernet library.
          3. Fixed LED control
        By Minde
*/

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x20, 0x3C }; //physical mac address
byte ip[] = { 192, 168, 1, 200 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 };                   //subnet mask
Server server(80);                                      //server port
byte sampledata=50;            //some sample data - outputs 2 (ascii = 50 DEC)             
int ledPin = 4;  // LED pin
char link[]="http://www.scienceprog.com/"; //link data
String readString = String(30); //string for fetching data from address
boolean LEDON = false; //LED status flag
void setup(){
//start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 4 to output
  pinMode(ledPin, OUTPUT); 
//enable serial datada print 
  Serial.begin(9600);
}
void loop(){
// Create a client connection
Client client = server.available();
  if (client) {
    while (client.connected()) {
   if (client.available()) {
    char c = client.read();
     //read char by char HTTP request
    if (readString.length() < 100)
      {
        //store characters to string
        readString += c; //replaces readString.append(c);
      } 
        //output chars to serial port
        Serial.print(c);
        //if HTTP request has ended
        if (c == '\n') {
          //dirty skip of "GET /favicon.ico HTTP/1.1"
          if (readString.indexOf("?") <0)
          {
            //skip everything
          }
          else
          //lets check if LED should be lighted
        if(readString.indexOf("L=1") >0)//replaces if(readString.contains("L=1"))
           {
             //led has to be turned ON
             digitalWrite(ledPin, HIGH);    // set the LED on
             LEDON = true;
           }else{
             //led has to be turned OFF
             digitalWrite(ledPin, 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();
          //set background to yellow
          client.print("<body style=background-color:yellow>");
          //send first heading
          client.println("<font color='red'><h1>HTTP test routines</font></h1>");
          client.println("<hr />");
         
          //controlling led via checkbox
          client.println("<h1>LED control</h1>");
          //address will look like http://192.168.1.110/?L=1 when submited
          if (LEDON)
          client.println("<form method=get name=LED><input type=checkbox name=L value=1 CHECKED>LED<br><input type=submit value=submit></form>");
          else
          client.println("<form method=get name=LED><input type=checkbox name=L value=1>LED<br><input type=submit value=submit></form>");     
          client.println("<br />");
          //printing LED status
          client.print("<font size='5'>LED status: ");
          if (LEDON)
              client.println("<font color='green' size='5'>ON");
          else
              client.println("<font color='grey' size='5'>OFF");     
          client.println("<hr />");
          client.println("<hr />");
          client.println("</body></html>");
          //clearing string for next read
          readString="";
          //stopping client
          client.stop();
            }
          }
        }
      }
 }     



This code below is using an actual switch on the board, and it will turn the LED on for 5 seconds. No web control
Code:
   
const int buttonPin = 2;

const int ledPin4 = 4;

unsigned long off_time4;

boolean ledState=false;
         // variable for reading the pushbutton status
int buttonState = 0;

void setup() {
 
  pinMode(ledPin4, OUTPUT);

  pinMode(buttonPin, INPUT);
 
  digitalWrite(ledPin4, LOW);

}

void loop(){

if ((ledState) && (millis()>=off_time4)) /* is it on and is it later or equal to off_time */
{
    digitalWrite(ledPin4,LOW);
    ledState = false;
}
else if (!ledState) /* is it off? */
{
    buttonState = digitalRead(buttonPin);
    if(buttonState == HIGH)
    {
        digitalWrite(ledPin4, HIGH);
        ledState = true;
        off_time4 = millis() + 5000;
    }
}


}

I'm trying to put some parts of the bottom code with the top code, but the LED does not turn off after 5 seconds, it just stays ON.

I can't seem to put these together. If you guys can help me out, that'll be great.
3  Using Arduino / Programming Questions / Re: just started using arduino ethernet sheild on: May 11, 2011, 04:06:04 pm
I just realized that I can't use this code because I have a different ethernet Shield (ENC28J60), i believe the code is for the WIZNET 5000.

Have to do some more researching  smiley-cry
4  Using Arduino / Programming Questions / Re: just started using arduino ethernet sheild on: May 11, 2011, 11:58:42 am
Okay, I have connected the ethernet shield to my router.

Now, am I suppose to open up a browser using according to my IP address? 192.168.0.106

If so, it shows up as broken page or web page not available.

Im using a ENC28J60 sheild btw
5  Using Arduino / Programming Questions / Re: just started using arduino ethernet sheild on: May 11, 2011, 11:27:43 am
Oh I see, thanks. I'll test it out again in a bit.

Is my setup right by the way?
6  Using Arduino / Programming Questions / Re: just started using arduino ethernet sheild on: May 11, 2011, 11:13:57 am
Hey zoomkat,

How come you did not change your mac address?  I thought you have to change it according to your PC or laptop.

I want to make sure I'm doing this right. I have
 -the USB cable connected to my laptop
 -ethernet cable connected from the sheild to my laptop ethernet port.

additional info:
and I am using Wi-Fi on my laptop via router.

this is what i get when I ping my Ip:

C:\Users\Allan Lee>ping 192.168.0.106

Pinging 192.168.0.106 with 32 bytes of data:
Reply from 192.168.0.106: bytes=32 time<1ms TTL=128
Reply from 192.168.0.106: bytes=32 time<1ms TTL=128
Reply from 192.168.0.106: bytes=32 time<1ms TTL=128
Reply from 192.168.0.106: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.0.106:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

7  Using Arduino / Programming Questions / Re: just started using arduino ethernet sheild on: May 09, 2011, 05:41:45 pm
Okay, I've now fix the code and it compiled alright.
So now, I think I'm suppose to go to the ethernet sheild's ip address. I typed in 192.168.0.106 on the browser , but it does not take me anywhere. Am I forgetting something?

Code:
#include <SPI.h>

#include <WString.h>
#include <Ethernet.h>
/*
Simple Ethernet Test
Arduino server outputs simple text to browser
and controlling LED with simple checkbox
The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* Basic FTDI breakout 5V
* LED connected to GND and digital pin 4 via resistor
By Minde
http://www.sciencprog.com/
*/
byte mac[] = { 0xF0, 0x7B, 0xCB, 0x20, 0xE9, 0x91 }; //physical mac address
byte ip[] = { 192, 168, 0, 106 }; // ip in lan
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(80); //server port
byte sampledata=50; //some sample data – outputs 2 (ascii = 50 DEC)
int ledPin = 13; // LED pin
char link[]="http://www.scienceprog.com/"; //link data
String readString = String(30); //string for fetching data from address
boolean LEDON = false; //LED status flag
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 4 to output
pinMode(ledPin, OUTPUT);
//enable serial datada print
Serial.begin(9600); }
void loop(){
// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 30) {
//store characters to string
readString.concat(c); }
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == '\n') {
//lets check if LED should be lighted
if(readString.indexOf("L=1")) {
//led has to be turned ON
digitalWrite(ledPin, HIGH); // set the LED on
LEDON = true;
}else{
//led has to be turned OFF
digitalWrite(ledPin, 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();
//set background to yellow
client.print("<body style=background-color:yellow>");
//send first heading
client.println("<font color=’red’><h1>HTTP test routines</font></h1>");
client.println("<hr />");
client.println("<hr />");
//output some sample data to browser
client.println("<font color='blue' size='5'>Sample data: ");
client.print(sampledata);//lets output some data
client.println("<br />");//some space between lines
client.println("<hr />");
//drawing simple table
client.println("<font color='green'>Simple table: ");
client.println("<br />");
client.println("<table border=1><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr>");
client.println("<tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>");
client.println("<br />");
client.println("<hr />");
//printing some link
client.println("<font color='blue' size='5'>Link: ");
client.print("<a href=");
client.print(link);
client.println(">Visit Scienceprog!</a>");
client.println("<br />");
client.println("<hr />");
//controlling led via checkbox
client.println("<h1>LED control</h1>");
//address will look like http://192.168.1.110/?L=1 when submited
client.println("<form method=get name=LED><input type=checkbox name=L value=1>LED<br><input type=submit value=submit></form>");
client.println("<br />");
//printing LED status
client.print("<font size='5'>LED status: ");
if (LEDON)
client.println("<font color='green' size='5'>ON");
else
client.println("<font color='grey' size='5'>OFF");
client.println("<hr />");
client.println("<hr />");
client.println("</body></html>");
//clearing string for next read
readString="";
//stopping client
client.stop();
}}}}}
8  Using Arduino / Programming Questions / Re: just started using arduino ethernet sheild on: May 05, 2011, 06:33:14 pm
okay, I've fixed the quotation issues, but now another error came up

'class String' has no member named 'append'

How do I fix this?

Im using Arduino 022 if that helps?

Code:
#include <WString.h>
#include <Ethernet.h>
/*
Simple Ethernet Test
Arduino server outputs simple text to browser
and controlling LED with simple checkbox
The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* Basic FTDI breakout 5V
* LED connected to GND and digital pin 4 via resistor
By Minde
http://www.sciencprog.com/
*/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 110 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(80); //server port
byte sampledata=50; //some sample data – outputs 2 (ascii = 50 DEC)
int ledPin = 4; // LED pin
char link[]="http://www.scienceprog.com/"; //link data
String readString = String(30); //string for fetching data from address
boolean LEDON = false; //LED status flag
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 4 to output
pinMode(ledPin, OUTPUT);
//enable serial datada print
Serial.begin(9600); }
void loop(){
// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 30) {
//store characters to string
readString.append(c); }
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == '\n') {
//lets check if LED should be lighted
if(readString.contains("L=1")) {
//led has to be turned ON
digitalWrite(ledPin, HIGH); // set the LED on
LEDON = true;
}else{
//led has to be turned OFF
digitalWrite(ledPin, 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();
//set background to yellow
client.print("<body style=background-color:yellow>");
//send first heading
client.println("<font color=’red’><h1>HTTP test routines</font></h1>");
client.println("<hr />");
client.println("<hr />");
//output some sample data to browser
client.println("<font color='blue' size='5'>Sample data: ");
client.print(sampledata);//lets output some data
client.println("<br />");//some space between lines
client.println("<hr />");
//drawing simple table
client.println("<font color='green'>Simple table: ");
client.println("<br />");
client.println("<table border=1><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr>");
client.println("<tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>");
client.println("<br />");
client.println("<hr />");
//printing some link
client.println("<font color='blue' size='5'>Link: ");
client.print("<a href=");
client.print(link);
client.println(">Visit Scienceprog!</a>");
client.println("<br />");
client.println("<hr />");
//controlling led via checkbox
client.println("<h1>LED control</h1>");
//address will look like http://192.168.1.110/?L=1 when submited
client.println("<form method=get name=LED><input type=checkbox name=L value=1>LED<br><input type=submit value=submit></form>");
client.println("<br />");
//printing LED status
client.print("<font size='5'>LED status: ");
if (LEDON)
client.println("<font color='green' size='5'>ON");
else
client.println("<font color='grey' size='5'>OFF");
client.println("<hr />");
client.println("<hr />");
client.println("</body></html>");
//clearing string for next read
readString="";
//stopping client
client.stop();
}}}}}
9  Using Arduino / Programming Questions / just started using arduino ethernet sheild on: May 03, 2011, 06:14:16 pm
I'm trying to test this code out from http://www.scienceprog.com/getting-hands-on-arduino-ethernet-shield/ at very bottom . When I compiled this code, I get an error saying that a "stray \ in program" on the underlined code.  The problem is that it is using double forward slashes, which comments out the entire link.  How do I fix this problem?

Code:
#include <WString.h>
#include <Ethernet.h>
/*
Simple Ethernet Test
Arduino server outputs simple text to browser
and controlling LED with simple checkbox
The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* Basic FTDI breakout 5V
* LED connected to GND and digital pin 4 via resistor
By Minde
http://www.sciencprog.com/
*/
byte mac[] = { 0xF0, 0x7B, 0xCB, 0x20, 0xE9, 0x91 }; //physical mac address
byte ip[] = { 134, 71, 201, 251 }; // ip in lan
byte gateway[] = { 134, 71, 201, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(80); //server port
byte sampledata=50; //some sample data – outputs 2 (ascii = 50 DEC)
int ledPin = 13; // LED pin
[u][b]char link[]= ”http://www.scienceprog.com/”;[/b][/u]
String readString = String(30); //string for fetching data from address
boolean LEDON = false; //LED status flag
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 4 to output
pinMode(ledPin, OUTPUT);
//enable serial datada print
Serial.begin(9600); }
void loop(){
// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 30) {
//store characters to string
readString.append(c); }
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == ‘\n’) {
//lets check if LED should be lighted
if(readString.contains(“L=1″)) {
//led has to be turned ON
digitalWrite(ledPin, HIGH); // set the LED on
LEDON = true;
}else{
//led has to be turned OFF
digitalWrite(ledPin, 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();
//set background to yellow
client.print(“<body style=background-color:yellow>”);
//send first heading
client.println(“<font color=’red’><h1>HTTP test routines</font></h1>”);
client.println(“<hr />”);
client.println(“<hr />”);
//output some sample data to browser
client.println(“<font color=’blue’ size=’5′>Sample data: “);
client.print(sampledata);//lets output some data
client.println(“<br />”);//some space between lines
client.println(“<hr />”);
//drawing simple table
client.println(“<font color=’green’>Simple table: “);
client.println(“<br />”);
client.println(“<table border=1><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr>”);
client.println(“<tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>”);
client.println(“<br />”);
client.println(“<hr />”);
//printing some link
client.println(“<font color=’blue’ size=’5′>Link: “);
client.print(“<a href=”);
client.print(link);
client.println(“>Visit Scienceprog!</a>”);
client.println(“<br />”);
client.println(“<hr />”);
//controlling led via checkbox
client.println(“<h1>LED control</h1>”);
//address will look like http://192.168.1.110/?L=1 when submited
client.println(“<form method=get name=LED><input type=checkbox name=L value=1>LED<br><input type=submit value=submit></form>”);
client.println(“<br />”);
//printing LED status
client.print(“<font size=’5′>LED status: “);
if (LEDON)
client.println(“<font color=’green’ size=’5′>ON”);
else
client.println(“<font color=’grey’ size=’5′>OFF”);
client.println(“<hr />”);
client.println(“<hr />”);
client.println(“</body></html>”);
//clearing string for next read
readString=”";
//stopping client
client.stop();
}}}}}
10  Using Arduino / Programming Questions / Re: Temperature and clock on 16 x 2 LCD, clearing issues on: April 26, 2011, 07:19:23 pm
Great it works fine, but now I have a colon in the front of the time.

":23:59:50"

update portion of code:
Code:
void printDigits(byte digits){
// utility function for digital clock display: prints preceding colon and leading 0

lcd.print(":");
if(digits < 10){
 
lcd.print('0');
}
lcd.print(digits,DEC);

}
void digitalClockDisplay(){

lcd.setCursor(0,0);

//lcd.print(" ");
if(DateTime.Hour<10)
lcd.setCursor(0,0);

// digital clock display of current time
printDigits(DateTime.Hour);
printDigits(DateTime.Minute);
printDigits(DateTime.Second);
}

11  Using Arduino / Programming Questions / Re: Temperature and clock on 16 x 2 LCD, clearing issues on: April 26, 2011, 05:59:41 pm
Sounds like a good idea, but

I'm kinda new to this so I'm not really sure how to do set it like 00:00:00.

Can you help me out?

12  Using Arduino / Programming Questions / Re: Temperature and clock on 16 x 2 LCD, clearing issues on: April 26, 2011, 02:57:41 pm
I need to use lcd.clear(); for the clock portion because if i don't , the clock does not roll over correctly. 

Initially i have it set at 23:59:50, and after ten 10 seconds, it resets to 0:00:001 and counts up, which  changes the layout of the clock.

13  Using Arduino / Programming Questions / Temperature and clock on 16 x 2 LCD, clearing issues on: April 26, 2011, 02:45:50 pm
I need the 2nd row to clear every time for the clock, not the 1st row.

Top row I have the temperature reading
Bottom row I have the clock reading.
When I add "lcd.clear();" on the void digitalClockDisplay() section at the bottom, it clears the top row instead, which I don't want.  

How do I fix this issue?

Code:
#include <LiquidCrystal440.h>

#include <OneWire.h>
#include <DallasTemperature.h>
#include <DateTime.h>
#include <DateTimeStrings.h>

#define dt_SHORT_DAY_STRINGS
#define dt_SHORT_MONTH_STRINGS

#define ONE_WIRE_BUS 9

OneWire oneWire(ONE_WIRE_BUS);
int heater;
DallasTemperature sensors(&oneWire);

DeviceAddress insideThermometer = { 0x10, 0x37, 0xBC, 0x1E, 0x02, 0x08, 0x00, 0xE9 };

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int LED1 = 10; // heater pin location
int LED2 = 31; // heater LED indicator

void setup()
{ DateTime.sync(DateTime.makeTime(50, 59, 23, 16, 10, 2010));
  lcd.begin(16,2);
  pinMode(LED1, OUTPUT);  // heater pin location
  pinMode(LED2, OUTPUT);  // heater LED indicator
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(insideThermometer, 10);
}



void loop()
{
  if(DateTime.available()) {
unsigned long prevtime = DateTime.now();
while( prevtime == DateTime.now() ) // wait for the second to rollover
;

DateTime.available(); //refresh the Date and time properties

digitalClockDisplay( ); // update digital clock
}
  sensors.requestTemperatures();
  printTemperature(insideThermometer);
  
  if (heater ==1){
    digitalWrite(LED1, HIGH); // Heater pin
    digitalWrite(LED2, HIGH); // Heater LED indicator
  } else {
    digitalWrite(LED1, LOW);  
    digitalWrite(LED2, LOW);
  
  }
 
}
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  
  lcd.setCursor(0,0);
  lcd.print("  Temp:");
  lcd.print(DallasTemperature::toFahrenheit(tempC));  
  lcd.print((char)223);
  lcd.print((char)70);
  
 
    
  if (DallasTemperature::toFahrenheit(tempC) < 75.00)
  heater = 1;
  else
  heater = 0;
}

void printDigits(byte digits){

// utility function for digital clock display: prints preceding colon and leading 0
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits,DEC);
}

void digitalClockDisplay(){

//lcd.print(" ");
if(DateTime.Hour <10)
lcd.setCursor(5,1);
lcd.setCursor(4,1);


// digital clock display of current time

lcd.print(DateTime.Hour,DEC);
printDigits(DateTime.Minute);
printDigits(DateTime.Second);
}

14  Using Arduino / Microcontrollers / arduino + LCD fades until other applications are done. on: April 22, 2011, 01:41:51 pm
We have a LCD display and 4 switches to turn on relays for certain applications.  I'm using atmega1280 and the problem that we have in our project is that the LCD display would fade every time the switches were powered.  Once the switches are off, LCD display goes back to normal.
Another problem is that when the switches are pressed, the response is slower unless it is firmly pressed. 

Is it because there is not enough voltage is supplied with everything ? Or a current problem?

 I am powering the arduino through USB cable btw, which is normally 5 volts I think.

 How can I solve this issue?

Will using a higher external power supply (9-12V) solve this problem?
15  Using Arduino / Programming Questions / Re: Turn on LED with switch using millis (solved) on: April 19, 2011, 05:50:20 pm
here you go theonlyone, this should work
Code:
#include <Servo.h>

Servo myservo;  // create servo object to control a servo

#define LED 13   
#define BUTTON 51

int val = 0;                    // variable for reading the pin status
int bounceCheck = 0;            // variable for debouncing
int cw = 0;                     // Servo cw value

void setup() {
  pinMode(BUTTON, INPUT);     // declare pushbutton as input
  pinMode(LED, OUTPUT);     // declare LED as output
}

void loop(){

  val = digitalRead(BUTTON);            //read input value
  delay(20);                              //wait 20ms
  bounceCheck = digitalRead(BUTTON);   //check again

  if(val == bounceCheck){                //if val is the same then not a bounce
    if (val == LOW) {                   //check if the input is LOW
     } else {
  digitalWrite(LED, HIGH);
  myservo.attach(9);               // white wire of servo to pin 9
  myservo.write(cw);
  delay(5000);
  digitalWrite(LED, LOW);
  myservo.detach();
}     
} //End if bounce check
} //end Loop

LED pin 13 just shows whether the servo is running or not running.
Red wire of servo to +5 V, white wire to pin 9, black to ground
Button pin 51

Also note that I am using a delay and not millis. I'll see if I can using millis instead of a delay.
Pages: [1] 2