help with alarm code

copachino:
i still have no posted the changes that NIck suggested....

Huh? Where is your changed code?

Try this out there is no debounce of the pin Interrupt 0 is digital pin 2 on the Uno baord

#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>

//const int ledPin = 3;
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("1220261654-BPUYlMFTyfs5ooSFSA62C57Ujeqnr9hdn7PARZm");
// you shouldn't post your token we could post on your Twitter account with this info...

// Message to post


void setup()
{
  digitalWrite(2, HIGH); //turn on internall pullup resistor
  attachInterrupt(0, ExtInt0Fall, FALLING); // there is no debouce of this pin
  delay(1000);
  Ethernet.begin(mac);
  // or you can use DHCP for autoomatic IP address configuration.
  // Ethernet.begin(mac);
  Serial.begin(9600);
  Serial.println("connecting ...");
  char msg[]="que odes";
}

void loop()
{
  if (ledState == HIGH)
    {
      ledState = LOW;
      int cont=0; // ? what is this for??
      Serial.println("High now");   
      delay(1000);
      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 ExtInt0Fall()
{
  ledState = HIGH;
}

Better read this:

There is no debounce because you haven't coded in a debounce.

Nick I made that for him to try, when it posts to Twitter that will take a little bit of time

Oh I see, sorry. I mistook you for the OP. :slight_smile:

You are right, the sending will debounce.

Frisky:
Try this out there is no debounce of the pin Interrupt 0 is digital pin 2 on the Uno baord

#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>

//const int ledPin = 3;
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("1220261654-BPUYlMFTyfs5ooSFSA62C57Ujeqnr9hdn7PARZm");
// you shouldn't post your token we could post on your Twitter account with this info...

// Message to post

void setup()
{
  digitalWrite(2, HIGH); //turn on internall pullup resistor
  attachInterrupt(0, ExtInt0Fall, FALLING); // there is no debouce of this pin
  delay(1000);
  Ethernet.begin(mac);
  // or you can use DHCP for autoomatic IP address configuration.
  // Ethernet.begin(mac);
  Serial.begin(9600);
  Serial.println("connecting ...");
  char msg[]="que odes";
}

void loop()
{
  if (ledState == HIGH)
    {
      ledState = LOW;//this turns the led off???
      int cont=0; // ? what is this for??//this was meant tobe a counter to print it with the msg so the msg could change and twitter did not give error
      Serial.println("High now");   
      delay(1000);
      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 ExtInt0Fall()
{
  ledState = HIGH;
}

the problem im still trapped its that still the code post only when i open the serial monitor in the IDE, only that this time it waits untill the led turns on.... but its possible to change that i don need to open the serial port???... i dont need any status msg on serial monitor, i mean the arduino will never be connected to a computer to run this program.....

  char msg[]="que odes";

A local variable that immediately goes out of scope. How useful is that?

the problem im still trapped its that still the code post only when i open the serial monitor in the IDE, only that this time it waits untill the led turns on.... but its possible to change that i don need to open the serial port???... i dont need any status msg on serial monitor, i mean the arduino will never be connected to a computer to run this program.....

The problem is that you don't use capital letters properly, and don't understand that ONE period or question mark is enough.

There is no reason that you should have to open the serial monitor. If you don't want to, then the Serial methods don't need to be present. Remove them.

Use LEDs to determine where you are getting to in the code.

thanks everyone for the help, i will try more a little late.

And for the variable char msg.... the lib of this code has tobe declared as char.... maybe i can post millis()... but i will have to study that

The code posted in reply #9, and quoted in reply #13, that I was referring to, won't even compile, since msg is declared in the wrong place.

int ledState = LOW;

...

  attachInterrupt(0, ExtInt0Fall, FALLING); // there is no debouce of this pin

 ...

void ExtInt0Fall()
{
  ledState = HIGH;
}

Variables shared between an ISR and main code should should be declared volatile.

Frisky:
Nick I made that for him to try, when it posts to Twitter that will take a little bit of time

void loop()
{
  if (ledState == HIGH)
    {
      ledState = LOW;

If the switch bounces, ledState will be set high again, despite how long sending the twitter takes, so that debounce won't work.

I thought you where posting that message to Twitter? Why would you need the serial monitor then?

i dont need the serial monitor, but, the problem its that until i dont open the serial monitor arduino wont post anything....

and sorry for my ignorance, but why would i need a debounce?? i just need to recognize the change of state on the pin, so if it bounce, until only post one msg its ok for me....

and for the twitter error for posting the same msg i think that using a counter and 5 different msgs in a switch sentence, and the variablechar msg[] should be declared as a pointer...

do u think this make any logic???, if so later this day i will post a program to do that...

also thanks for your help it really helps me a lot

Post all of your current code please.

Depending on how it is written the debounce stops multiple messages being sent to Twitter.

this is my code but i doesnt compile, i cant find the error...

#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 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[20];
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()

 int count=0;
  if (ledState == HIGH)
  {
    LedState==LOW;
    
    Swtich (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;
   
 }

but i doesnt compile, i cant find the error...

And we can't see them...

char* msg[20];

This is an array of 20 pointers, not a pointer to 20 characters, or an array of 20 characters.

i used that because IDE told that that if i use
char* msg[]; then the zise its unknown,

still the error says that i need an initializer before if functions....

also doesnot allow me to use the normal { on the start of the void loop()..... so im not sure where its my mistake... maybe i have many of then

still the error says that i need an initializer before if functions....

There is a big difference between

char *msg[20];

and

char msg[20];

The first is an array of 20 uninitialized pointers to characters. The second is an array of 20 characters.

Which do you need? I'm guessing that 20 uninitialized pointers are useless.

yes, but i need an array with pointer, so in the switch case depending on the counter, the pointer msg will be referenced to the array with the message

char* msg its the pointer i need..

its the pointer i need..

What does that point to? Without making it point somewhere, you can't store data at the pointed to location.