Pages: [1] 2 3 4   Go Down
Author Topic: help with alarm code  (Read 3355 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

hi all...

i just foun this code but maybe im not editing it right....

what i want with the code its ust to simple post a tweet every time my led turns high....

but have many troubles, for example the code just post when i open serial monitor, second when i change the code for the led input, then it doesnt post anything,
and last, its that twitter does not acept my msg cos it said its the same tweet, so how can i change that

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>

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");

// Message to post


void setup()
{
 
  pinMode(ledPin, INPUT);
  delay(1000);
  Ethernet.begin(mac);
  // or you can use DHCP for autoomatic IP address configuration.
  // Ethernet.begin(mac);
  Serial.begin(9600);
 
  Serial.println("connecting ...");
 
}

void loop()
{
 
  Serial.println(ledState);
  char msg[]="que odes";
  if (ledState == HIGH)
  {
 
  int cont=0;
  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.");
   
   
  }
  }
}
Logged

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

Code:
  if (ledState == HIGH)
    ...

Your code never reads or changes ledState.
Logged

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

so if i attacht it to an interrupt and read the rising, the arduino will know that, i see that error, thanks, but how can i change that arduino knwos that state and post the msg without open the serial monitor???
Logged

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

Where is the attacthinterrupt at I see nothing for setting up or handling an external interrupt.
Logged

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

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


Logged

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

In setup you need to attachinterrupt with some parameters. See link for learn to use that function.
http://arduino.cc/en/Reference/AttachInterrupt
Logged

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

i know how to do that, the problem is that i cant change how to post a msg without opening the serial port
Logged

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

Why do you think you need an interrupt?
Logged

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

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

Huh? Where is your changed code?
Logged

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

Try this out there is no debounce of the pin Interrupt 0 is digital pin 2 on the Uno baord
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>

//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;

Logged

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

Better read this:

http://www.gammon.com.au/switches


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

Chicago
Offline Offline
Full Member
***
Karma: 0
Posts: 113
Arduino rocks
View Profile
 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 
Logged

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

Oh I see, sorry. I mistook you for the OP. smiley

You are right, the sending will debounce.
Logged

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

Try this out there is no debounce of the pin Interrupt 0 is digital pin 2 on the Uno baord
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>

//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;//[color=red]this turns the led off???[/color]
      int cont=0; // ? what is this for??//[color=red]this was meant tobe a counter to print it with the msg so the msg could change and twitter did not give error[/color]
      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.....
Logged

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

Code:
  char msg[]="que odes";
A local variable that immediately goes out of scope. How useful is that?

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

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