Pages: 1 [2] 3   Go Down
Author Topic: Newbie Questions (Soz lol)  (Read 2964 times)
0 Members and 1 Guest are viewing this topic.
AUS,Downunder
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks!!!:)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i lol'd
Quote
Don't forget, that like yourself, many people here don't have English as a first language,

here in australia english sorta is our first language and it is mine also i just suck at wrighting lol
Logged

Cod modder/mapper

AUS,Downunder
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks!!!:)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok so as far as my script goes i've got it working with one stiwch and added in whats needed for the 2'nd im just not sure what i need to do to make it work in the LOOP
Code:
/* testing
 * ------------------
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */
#include <IRremote.h>

IRsend irsend;

int inPin = 2; // choose the input pin (for a pushbutton)
int inpin1 = 4; // as pin 3 is for IRled with Pwm..
int val = 0;     // variable for reading the pin status

void setup() {

  pinMode(inPin, INPUT);    // declare pushbutton as input
  pinMode(inpin1, INPUT);
  Serial.begin(9600);
}

void loop(){
  val = digitalRead(inPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button released)
   (Serial.read() != -1); {
    for (int i = 0; i < 1; i++) {
      irsend.sendNEC(0x2FDD827, 32); // My TV CHan-up code
      delay(40);
    }
   }
  }
}
irremote.h
Code:
 
/*
 * IRremote
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.htm http://arcfn.com
 *
 * Interrupt code based on NECIRrcv by Joe Knapp
 * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
 * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
 */

#ifndef IRremote_h
#define IRremote_h

#include "IRremoteInt.h"

// The following are compile-time library options.
// If you change them, recompile the library.
// If DEBUG is defined, a lot of debugging output will be printed during decoding.
// TEST must be defined for the IRtest unittests to work.  It will make some
// methods virtual, which will be slightly slower, which is why it is optional.
// #define DEBUG
// #define TEST

// Information on a generic space encoding code.
// This is a code that varies the mark width (or the space
// width) to distingish bits.
class space_enc_data {
public:
  int headerMark; // Mark time for header in us
  int headerSpace; // Space time for header in us
  int mark0; // Mark time in us for 0 bit
  int space0; // Space time in us for 0 bit
  int mark1; // Mark time in us for 1 bit
  int space1; // Space time in us for 1 bit
  int trailer; // Trailer mark time in us or 0
  int frequency; // Not used by IRrecv
};

// Results returned from the decoder

class decode_results {
public:
  int decode_type; // SPACE_ENC, RC5, RC6, NEC_REPEAT, UNKNOWN
  unsigned long long value; // Decoded value
  int bits; // Number of bits in decoded value
  volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks
  int rawlen; // Number of records in rawbuf.
  class space_enc_data spaceEncData;
};

// Values for decode_type
#define NEC_REPEAT 1
#define RC5 3
#define RC6 4
#define SPACE_ENC 7 // Generic space encoding
#define UNKNOWN -1

// Decoded value for NEC when a repeat code is received
#define REPEAT 0xffffffff

// main class for receiving IR
class IRrecv
{
public:
  IRrecv(int recvpin);
  int decode(decode_results *results);
  void enableIRIn();
  void pause();
  void resume(); // deprecated
private:
  // These are called by decode
  int getRClevel(decode_results *results, int *offset, int *used, int t1);
  long decodeSpaceEnc(decode_results *results);
  long decodeNecRepeat(decode_results *results);
  long decodeRC5(decode_results *results);
  long decodeRC6(decode_results *results);
  long decodeHash(decode_results *results);
  int compare(unsigned int oldval, unsigned int newval);
  volatile irparams_t irparams; // Receive state information
}
;

// Only used for testing; can remove virtual for shorter code
#ifdef TEST
#define VIRTUAL virtual
#else
#define VIRTUAL
#endif

class IRsend
{
public:
  IRsend() {}
  void sendSpaceEnc(unsigned long long data, int nbits, space_enc_data *spaceEncData);
  void sendNEC(unsigned long data, int nbits); // deprecated
  void sendSony(unsigned long data, int nbits); // deprecated
  void sendRaw(unsigned int buf[], int len, int hz);
  void sendRC5(unsigned long data, int nbits);
  void sendRC6(unsigned long data, int nbits);
  // private:
  void enableIROut(int khz);
  VIRTUAL void mark(int usec);
  VIRTUAL void space(int usec);
}
;

// Some useful constants

#define USECPERTICK 50  // microseconds per clock interrupt tick

// Marks tend to be 100us too long, and spaces 100us too short
// when received due to sensor lag.
#define MARK_EXCESS 100

#endif
 
    
    
    
Logged

Cod modder/mapper

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24322
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
(Serial.read() != -1); {

Is there supposed to be an "if" there?
If there is, there shouldn't be a ";".
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

AUS,Downunder
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks!!!:)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

im not sure if there was ment to be but i tryed it
Code:
if (Serial.read() != -1) {
and that stoped even the first code geting sent so put back in the ;
Code:
if (Serial.read() != -1); {
and it started working again but still not the 2'nd button so puting in "if " seemed to make no difference ,with or with out it the 2'nd ircommand still isnt being send  :'(
Logged

Cod modder/mapper

AUS,Downunder
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks!!!:)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

would a Picture of my breedboard/layout help???
Logged

Cod modder/mapper

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

What is supposed to be sending serial data?
Logged

AUS,Downunder
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks!!!:)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

im really not to sure why thats there i just copyed the IRsendDemo from Ken Shirriff's alwsome library http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html


edit thats the old one here's the updated one im now useing
https://github.com/shirriff/Arduino-IRremote
« Last Edit: November 05, 2010, 09:37:44 pm by rotceh_dnih » Logged

Cod modder/mapper

AUS,Downunder
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks!!!:)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok here's some photo's sorry about my iphone its all i have to take a picture with at the moment






and this is what i what to do in the end

« Last Edit: November 05, 2010, 11:07:36 pm by rotceh_dnih » Logged

Cod modder/mapper

AUS,Downunder
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks!!!:)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

mmmk i've spent manny hours on this and have managed to get it to work smiley  smiley smiley

i only have 2 1k resisters so have only made it two buttons but more should work fine now smiley
here's the code i got to work there's still some bug's like the channel button will still change between 1 two 3 channnel's not sure but maybe some debouceing code would help not sure

Quote


#include <IRremote.h>

IRsend irsend;

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int buttonPin1 = 4;     // the number of the pushbutton pin
     // the number of the LED pin

// variables will change:
int buttonState = 0;
int buttonState1 = 0;          // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
     Serial.begin(9600);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
pinMode(buttonPin1, INPUT);    
}

void loop(){

      // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);
    if (buttonState1 == HIGH) {    
    // turn LED on:    
    for (int i = 0; i < 3; i++) // somehow needed for timeing the power on and off without it the tv turns off then back on
    irsend.sendNEC(0x2FD48B7, 32); // MY TV power code
    delay(40);
    }
    else {
      buttonState = digitalRead(buttonPin);
      if (buttonState == HIGH) {
        for (int i = 0; i < 1; i++) //same as above but changed < 3 to < 1 coz its would change 3 chanenns at a time lol but still dosnt work though i thought it would
        irsend.sendNEC(0x2FDF807, 32); // MY TV Chan-up code
        delay(40);
      }
    }
}
        

Logged

Cod modder/mapper

Central Europe
Offline Offline
Edison Member
*
Karma: 6
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
mmmk i've spent manny hours on this and have managed to get it to work

i only have 2 1k resisters so have only made it two buttons but more should work fine now

Congratulations. About not having enough resistors, this opens the venue to learn the next thing: Pull-up resistors. As the Arduino has integrated pull up resistors you can activate, you have the option to connect buttons without need of external resistors. Your code changes slightly but nothing impossible to handle in software.

For the hardware:
Connect your button between your Arduino digital pin and GND (not to +5V). When you press the button you're going to drag the votage down to 0 on the pin. No need for any resistors.

For the software, setting up the pin needs one additional line per pin.
Code:
pinMode(buttonPin, INPUT);
[glow]digitalWrite (buttonPin, HIGH);[/glow] // Activate internal pull-up
By setting the input pin to HIGH, the internal pull-up resistor is activated. Now if your button is open, the pin will read HIGH because a little current flows inside the Arduino to the input. When you press the button, the pin will be connected to the ground and you will read LOW. As the internal pull-up resistors are quite big (20kOhm if I remember correctly) there's very little current flowing.

The main difference between the regular button example and this one is:
 digitalRead(buttonPin) == HIGH: Button is open
 digitalRead(buttonPin) == LOW: Button is closed.

So in your code you have to change the line testing the button state to:
Code:
buttonState = digitalRead(buttonPin);
if (buttonState == [glow]LOW[/glow]) {
...

That's all there is. You just saved one resistor per button. Try it out.

Korman
« Last Edit: November 06, 2010, 03:42:39 am by Korman » Logged

AUS,Downunder
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks!!!:)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wow thank you very much that worked like a charm
but now im stuck at two button's i think it might have something todo with the "Else" command i put in as i dont understand programeing whatso ever im not sure but it is good to make progress smiley smiley
here my code
Code:
#include <IRremote.h>

IRsend irsend;

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int buttonPin1 = 4;     // the number of the pushbutton pin
const int buttonPin2 = 5;
const int buttonPin3 = 6;
const int buttonPin4 = 7;
     // the number of the LED pin

// variables will change:
int buttonState = 0;
int buttonState1 = 0;       // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;

void setup() {
  // initialize the LED pin as an output:
     Serial.begin(9600);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  digitalWrite (buttonPin, HIGH);
pinMode(buttonPin1, INPUT);    
digitalWrite (buttonPin1, HIGH);
pinMode(buttonPin2, INPUT);
digitalWrite (buttonPin2, HIGH);
pinMode(buttonPin3, INPUT);
digitalWrite (buttonPin3, HIGH);
pinMode(buttonPin4, INPUT);
digitalWrite (buttonPin4, HIGH);
}

void loop(){

      // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);
    if (buttonState1 == LOW) {    
    // turn LED on:    
    for (int i = 0; i < 3; i++) // somehow needed for timeing the power on and off without it the tv turns off then back on
    irsend.sendNEC(0x2FD48B7, 32); // MY TV power code
    delay(40);
    }
    else {
      buttonState = digitalRead(buttonPin);
      if (buttonState == LOW) {
        for (int i = 0; i < 1; i++) //same as above but changed < 3 to < 1 coz its would change 3 chanenns at a time lol
        irsend.sendNEC(0x2FDF807, 32); // MY TV Chan-down code
        delay(40);
    }
    else {
      buttonState2 = digitalRead(buttonPin2);
      if (buttonState == LOW) {
        for (int i = 0; i < 1; i++) //same as above but changed < 3 to < 1 coz its would change 3 chanenns at a time lol
        irsend.sendNEC(0x2FDD827, 32); // MY TV Chan-up code
        delay(40);
    }
    else {
      buttonState3 = digitalRead(buttonPin3);
      if (buttonState == LOW) {
        for (int i = 0; i < 1; i++) //same as above but changed < 3 to < 1 coz its would change 3 chanenns at a time lol
        irsend.sendNEC(0x2FD7887, 32); // MY TV Vol-down code
        delay(40);
    }
    else {
      buttonState4 = digitalRead(buttonPin4);
      if (buttonState == LOW) {
        for (int i = 0; i < 1; i++) //same as above but changed < 3 to < 1 coz its would change 3 chanenns at a time lol
        irsend.sendNEC(0x2FD58A7, 32); // MY TV Vol-UP code
        delay(40);
      }
    }
    }
    }
    }
}
and im not sure if i need all those buttonState's,just put tem there in case
Logged

Cod modder/mapper

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

You should not be using nested if/else statements.

You want to do something if a button is pressed, and nothing if it isn't pressed, so you don't need the else block.

The state of, and action to take, if a button is pressed is completely independent of the state of other buttons.
Logged

AUS,Downunder
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks!!!:)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok figered it out its works with or without the else/if commands
but the reason the 3,4,5 button's wern't working was because i forgot to put in the buttonState number ie "if (buttonState4 == LOW) " i didnt put the 4 in lol,
anywawys here's my working code with a lcd witch i plan on displaying what button is being pressed like power and stuff
Quote
#include <LiquidCrystal.h>

#include <IRremote.h>

IRsend irsend;

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int buttonPin1 = 4;     // the number of the pushbutton pin
const int buttonPin2 = 5;
const int buttonPin3 = 6;
const int buttonPin4 = 7;
     // the number of the LED pin

// variables will change:
int buttonState = 0;
int buttonState1 = 0;       // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

void setup() {
  // initialize the LED pin as an output:
     Serial.begin(9600);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  digitalWrite (buttonPin, HIGH);
pinMode(buttonPin1, INPUT);    
digitalWrite (buttonPin1, HIGH);
pinMode(buttonPin2, INPUT);
digitalWrite (buttonPin2, HIGH);
pinMode(buttonPin3, INPUT);
digitalWrite (buttonPin3, HIGH);
pinMode(buttonPin4, INPUT);
digitalWrite (buttonPin4, HIGH);
lcd.begin(16, 2);
lcd.print("hectic IRremote");
lcd.setCursor(0, 1);
lcd.print("V 1.2 Beta");
}

void loop(){

      // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);
    if (buttonState1 == LOW)
  {  
    // turn LED on:    
    for (int i = 0; i < 3; i++) // somehow needed for timeing the power on and off without it the tv turns off then back on
    irsend.sendNEC(0x2FD48B7, 32); // MY TV power code
    delay(40);
    }
      buttonState = digitalRead(buttonPin);
      if (buttonState == LOW)
      {
        for (int i = 0; i < 1; i++) //same as above but changed < 3 to < 1 coz its would change 3 chanenns at a time lol
        irsend.sendNEC(0x2FDF807, 32); // MY TV Chan-down code
        delay(40);
      }
  
      buttonState2 = digitalRead(buttonPin2);
      if (buttonState2 == LOW)
      {
        for (int i = 0; i < 1; i++) //same as above but changed < 3 to < 1 coz its would change 3 chanenns at a time lol
        irsend.sendNEC(0x2FDD827, 32); // MY TV Chan-up code
        delay(40);
      }
  
      buttonState3 = digitalRead(buttonPin3);
      if (buttonState3 == LOW)
      {

        for (int i = 0; i < 1; i++) //same as above but changed < 3 to < 1 coz its would change 3 chanenns at a time lol
        irsend.sendNEC(0x2FD7887, 32); // MY TV Vol-down code
        delay(40);
      }

    
      buttonState4 = digitalRead(buttonPin4);
      if (buttonState4 == LOW)
      {
        for (int i = 0; i < 1; i++) //same as above but changed < 3 to < 1 coz its would change 3 chanenns at a time lol
        irsend.sendNEC(0x2FD58A7, 32); // MY TV Vol-UP code
        delay(40);
      }
}
and a picture of my setup smiley

Logged

Cod modder/mapper

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24322
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
for (int i = 0; i < 1; i++)
Novel.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

AUS,Downunder
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks!!!:)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oh could you Plaese explane what that bit is ment to do ????
i remember changeing the val to 1 coz i thought it would not change the channel 3 times when i press the button once,,but yea i really dont know whats it mean's and would love to know smiley plz
Logged

Cod modder/mapper

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