Go Down

Topic: help with alarm code (Read 4 times) previous topic - next topic

Nick Gammon

Code: [Select]

    switch (count)
    { case 1:
    msg =& str1;
    count++;
    break;
   
    case 2:
    msg =& str2;
    count++;
    break;
   
    case 3:
    msg =& str3;
    count++;
    break;
   
   
    case 4:
    msg =& str4;
    count++;
    break;
   
    case 5:
    msg =& str5;
    count++;
    break;
    case 6:
    msg =& str6;
    count=0;
    break;
    }
     }


And read up on using arrays. Won't you get bored copying and pasting when you end up with 100 messages?

copachino


Code: [Select]

  if (LedState == HIGH)
  {
    LedState==LOW;


Time to start reading a basic C tutorial. Don't just thrash around posting whatever comes into your head.

Do some simple programs first. Get the hang of it. Trying to do Twitter in your first code is ridiculous.


nick its not my first code, but i did have pratice for long so im kind stck here, that if sentence was proposed by someone on tne debounce thing, so im not used to that i ust leave it that way.....

copachino

so finaly have manage to get it work this its the code

Code: [Select]
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>

// The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later.
// Please uncomment below in Arduino IDE 0022 or earlier.
//#include <EthernetDNS.h>
int count=0;
int LedState=LOW ;
// Ethernet Shield Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
byte ip[] = { 192, 168, 2, 250 };

// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("YOUR-TOKEN-HERE");

// Message to post
char* msg;
char str1[]="post one";
char str2[]="post two";
char str3[]="post three";
char str4[]="post four";
char str5[]="post five";
char str6[]="post six";

void setup()
{
  digitalWrite(2, HIGH);
  attachInterrupt(0, alarm, RISING);
 
  delay(1000);
  Ethernet.begin(mac);
  // or you can use DHCP for autoomatic IP address configuration.
  // Ethernet.begin(mac);
  Serial.begin(9600);
 

}
void loop()

{
  if (LedState == HIGH)
  {
    LedState=LOW;
   
    switch (count)
    { case 1:
    msg = str1;
    count++;
    break;
   
    case 2:
    msg = str2;
    count++;
    break;
   
    case 3:
    msg = str3;
    count++;
    break;
   
   
    case 4:
    msg = str4;
    count++;
    break;
   
    case 5:
    msg = str5;
    count++;
    break;
    case 6:
    msg = str6;
    count=0;
    break;
    }
     }
   
   
   
   Serial.println("connecting ...");
  if (twitter.post(msg)) {
    // Specify &Serial to output received response to Serial.
    // If no output is required, you can just omit the argument, e.g.
    // int status = twitter.wait();
    int status = twitter.wait(&Serial);
    if (status == 200) {
      Serial.println("OK.");
    } else {
      Serial.print("failed : code ");
      Serial.println(status);
    }
  } else {
    Serial.println("connection failed.");
  }

 
 

}

void alarm()
{
  LedState = HIGH;
   
}

Go Up