Pages: 1 [2] 3 4   Go Down
Author Topic: help with alarm code  (Read 3337 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 473
Posts: 18695
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.

http://www.gammon.com.au/interrupts
« Last Edit: March 12, 2013, 03:19:42 pm by Nick Gammon » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 473
Posts: 18695
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.
Logged

Chicago
Offline Offline
Full Member
***
Karma: 0
Posts: 113
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 variable
Code:
char 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
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 473
Posts: 18695
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Post all of your current code please.

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

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#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;
   
 }
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but i doesnt compile, i cant find the error...
And we can't see them...

Code:
char* msg[20];
This is an array of 20 pointers, not a pointer to 20 characters, or an array of 20 characters.
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 i used that because IDE told that that if i use
Code:
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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
still the error says that i need an initializer before if  functions....
There is a big difference between
Code:
char *msg[20];
and
Code:
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.
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
char* msg
its the pointer i need..
« Last Edit: March 14, 2013, 11:57:27 am by copachino » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3347
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
char* msg

Except msg doesn't point to anything. If it was written like this:

Code:
char msg[20]

msg now points to a char that has 19 additional slots available for use.
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, i have made some crrections but, still IDE says expected initializer before 'if'

Code:
[quote]
  [#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[26];
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;
   
    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;
   
 }
Logged

Pages: 1 [2] 3 4   Go Up
Jump to: