Show Posts
Pages: 1 ... 79 80 [81] 82 83 ... 97
1201  Using Arduino / Project Guidance / pin 2 pullup res on: April 17, 2011, 02:38:58 am
On a freestanding board I saw it is recommended to put a 10 k pullup resistor from pin2 to Vcc to avoid noise.

Can I just set it to an input and take it high to enable the internal pullup?  
1202  Development / Suggestions for the Arduino Project / Re: Basic suggestions for IDE usability improvements on: April 17, 2011, 02:35:39 am
The active port would be very handy,  I have been developing a telemetry system with 2 arduinos plugged in to the one PC, and I keep ending up with 2 receivers or 2 transmitters when I forget to swap the port.
1203  Using Arduino / Project Guidance / Re: Tone library and millis clash? on: April 17, 2011, 02:30:55 am
I think just one, I want to make a horn type sound for the end of a timeout period, a square wave into a fet amp and speaker.
Not worried about distortion, just lots of noise ( that's what my late Dad used to say about the Beatles :-) )
1204  Using Arduino / Project Guidance / Tone library and millis clash? on: April 17, 2011, 01:22:03 am

In the description of the Tone library, it states:-

" Also, although it's the last timer to be allocated, timer 0 (which is used for millis() among other things) will be affected if used. "


Does this mean only while the tone is playing?  or will my timing of my project which uses the millis for a countdown timer be compromised by merely calling up the tone library?

I want to sound a horn at the end of the countdown, so I dont need the timer then..  I just need confirmation
1205  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 16, 2011, 05:10:01 pm
Right thanks everyone, its working !

And a stupid thing I had forgotten was that when it was just counting down seconds, I was worried about losing the first second, so I started the clock from 24.9 seconds for the 24 second timer.
This was because as soon as you hit "run" it would flick over to 23, but the horn would sound ( and the pause would go high )as soon as the count went from 1 to 0, so it was running for only 23 seconds.  ( imagine if I wanted a 2 second countdown - it would be 1 second )

I am now counting down in 10ths of a second, and displaying the last ten seconds as 9.9 etc, so the 0 doesn't happen until a second after the 1 has changed to 0.9 and it counts right down to 0.0 .

So now I start at the "proper" 24 secs.   It pauses and restarts from the fraction of a second fine too.

1206  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 09:29:14 pm
right, I see now, I will give it a try, thanks
1207  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 08:49:14 pm
Thanks Rob
I will try that code, I do define the array msg as 4 in the setup, is that part of it?

I will stick the scope on and see what the transmission length is, I should have done that anyway.

I will also look up the hex/dec story  when I get a chance ( 4am and I am soldering hundreds of LEDs for a rush job! )


1208  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 04:46:34 am
Thanks, that makes sense now, so much to learn, so little time
1209  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 04:15:03 am
   tens = (secNibble10) ? digitTable [ secNibble10] : 0; // leading zero blanking
  units = digitTable [secNibble];
  units |= ( period) ? B10000000 : 0;

Whats the question mark ?   I am trying to understand this part...
1210  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 03:48:04 am
Thanks AWOL,, yes I need to tidy up and learn lots of short cuts, I actually saw a lookup table like this last night, but now you have shown me the right way to do it.

I must also find how to run a function if something has changed, but I just want to see if I can get the countdown working OK first.
1211  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 02:53:08 am
Good luck with the move Rob,  so will you be "somewhere else in Australia" on your avatar tomorrow?
1212  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 02:50:31 am
part 2 of the Rx



Code:
void show ()
{
  // WANT TO PUT IF  ( T OR PERIOD HAS CHANGED) DO DISPLAY

  if ( T >= 99 ) {
    divided = T/10;
  }
  else
  {
    divided = T ;
    period = HIGH;
  }

  if ( T == 0 ) {
    period = LOW ;
  }

  secNibble10 = divided/10;  // extact the tens digit from the time
  secNibble = divided%10;  // extract the units digit

  switch ( secNibble10)  {
    //   segments   a b c d e f g dp
  case 0:
    tens = B00000000;
    break;

  case 1:
    tens = B00110000;
    break;
  case 2:
    tens = B01101101;
    break;
  case 3:
    tens = B01111001;
    break;
  case 4:
    tens = B00110011;
    break;
  case 5:
    tens = B01011011;
    break;
  case 6:
    tens = B01011111;
    break;
  case 7:
    tens = B01110000;
    break;
  case 8:
    tens = B01111111;
    break;
  case 9:
    tens = B01111011;
    break;
     }  // end of switch 10s
  /////////////////////////////////////////////////////////////////////////

  //try 2 choices here to have the period dot on

  if ( period == LOW ){

    switch ( secNibble)  {
      //   segments   a b c d e f g dp
    case 0:
      units = B01111110;
      break;
    case 1:
      units = B00110000;
      break;
    case 2:
      units = B01101101;
      break;
    case 3:
      units = B01111001;
      break;
    case 4:
      units = B00110011;
      break;
    case 5:
      units = B01011011;
      break;
    case 6:
      units = B01011111;
      break;
    case 7:
      units = B01110000;
      break;
    case 8:
      units = B01111111;
      break;
    case 9:
      units = B01111011;
      break;
    }
  }

  if ( period == HIGH ){

    switch ( secNibble)  {
      //   segments   a b c d e f g dp ( reverse ! )
    case 0:
      units = B11111110;
      break;
    case 1:
      units = B10110000;
      break;
    case 2:
      units = B11101101;
      break;
    case 3:
      units = B11111001;
      break;
    case 4:
      units = B10110011;
      break;
    case 5:
      units = B11011011;
      break;
    case 6:
      units = B11011111;
      break;
    case 7:
      units = B11110000;
      break;
    case 8:
      units = B11111111;
      break;
    case 9:
      units = B11111011;
      break;
      Serial.print(" units ") ; 
      Serial.println(units) ; 

    }


  }//  end of the switch sec nibble

  digitalWrite(latchPin, LOW);


  shiftOut(dataPin, clockPin, LSBFIRST, tens);
  shiftOut(dataPin, clockPin, LSBFIRST, units);

  digitalWrite(latchPin, HIGH);

}  // end of showT function







1213  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 02:48:59 am
and part one of the Rx;

Code:
#include <VirtualWire.h>
#define ledPin 13 
#define latchPin 19  // rck
#define clockPin 18  // sck
#define dataPin 16   // ser in
#define blankPin 15  // notG
#define clearPin 17  // not SCLR
int divided;
byte tens;
byte units;
int secNibble10;
int secNibble;
int PIN;
int key;
int T = 0;
int toot = LOW;
int pause = HIGH;
int blank = LOW;
int horn = LOW;
int toothorn = LOW;
int period = LOW;
//int tens;
//int units;
static unsigned long previousMillis = 0;        // will store last time LED was updated
static unsigned long previoustootMillis = 0;
static unsigned long previoushornMillis = 0;
static unsigned long timertarget = 0;

int SW0Pin = 3;               // bits to read in unique address - LSB
int SW1Pin = 4;               // bits to read in unique address
int SW2Pin = 5;               // bits to read in unique address
int SW3Pin = 6;               // bits to read in unique address - MSB
int address = 0;            // bits put together afteer reading switches
int add0;
int add1;
int add2;
int add3;
long previousflashMillis = 0;        // will store last time LED was updated
long interval = 250;           // interval at which to blink (milliseconds)

void setup()
{

  pinMode(SW0Pin, INPUT); // LSB of remote Address
  digitalWrite(SW0Pin, HIGH);
  byte add0 = 0; // read the value of SW0
  pinMode(SW1Pin, INPUT); // LSB+1
  digitalWrite(SW1Pin, HIGH);
  byte add1= 0;
  pinMode(SW2Pin, INPUT);  // LSB+2
  digitalWrite(SW2Pin, HIGH);
  byte add2 = 0;
  pinMode(SW3Pin, INPUT);  // MSB of address
  digitalWrite(SW3Pin, HIGH);
  byte add3 = 0;


  digitalWrite(clearPin, HIGH);
  digitalWrite(blankPin, LOW);
  // put our address together
  // read our expansion address
  add3 = digitalRead(SW3Pin);
  // shift it left 3 places
  add3 = add3 << 3;
  add2 = digitalRead(SW2Pin);
  // shift it left 2 places
  add2 = add2 << 2;
  add1 = digitalRead(SW1Pin);
  // shift it left 1 place
  add1 = add1 << 1;
  add0 = digitalRead(SW0Pin);
  // now OR it together
  address = address|add3;
  address = address|add2;
  address = address|add1;
  address = address|add0;
  Serial.println("Rx PIN is: ");
  Serial.println(address, BIN);
  Serial.begin(9600); // Debugging only
  Serial.println("setup");
  pinMode(ledPin, OUTPUT);
  pinMode(blankPin, OUTPUT);
  pinMode ( latchPin, OUTPUT);
  pinMode ( clockPin, OUTPUT);
  pinMode ( dataPin, OUTPUT);
  pinMode (clearPin , OUTPUT);
  digitalWrite(ledPin, LOW);

  vw_set_rx_pin(9);        // set Rx
  vw_setup(4000); // Bits per sec
  vw_rx_start();   
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void loop ()
{
  digitalWrite(blankPin, blank);

  if (T >= 0 && pause == LOW ) {    //  if the countdown is running and not 0 yet keep
    // decrementing timer

    static unsigned long previousMillis;
    if(millis() > previousMillis){
      previousMillis = millis() + 100;

      T -- ;                               // countdown 1/10th sec
      Serial.println(T);     
      Serial.println("");
      if ( T== -1 ){
        T = 0 ;
      }
    }
  }

  if ( pause == HIGH && T ) {   //  if paused but above zero, flash period dot

    unsigned long currentflashMillis = millis();
    if(millis () - previousflashMillis > interval) {
      // save the last time you blinked the LED
      previousflashMillis = currentflashMillis;     // if the LED is off turn it on and vice-versa:
      if (period == LOW)
      {
        period = HIGH;
      }
      else
      {
        period = LOW;
      }


    }
  }

  if ( T >= 100 && pause == LOW ) {   // switch off period dot during normal countdown
    period = LOW ;
  }


  ///////////////////////////////////////////////////////////////////////////////////////

  show ();  // runs the display countdown and update function

  ////////////////////////////////////////////////////////////////

  if ( T <= 0 && pause == 0 && horn == 0) { // if countdown reaches zero and horn is off
    horn = 1;   
    Serial.print("horn is   ");     
    Serial.println(horn); 
    pause = 1;
    digitalWrite(ledPin, horn);
    delay ( 4000 );
    horn = 0;
    //  digitalWrite(ledPin, horn);
    Serial.print("horn is   ");     
    Serial.println(horn); 
  }

  digitalWrite(ledPin, horn);
  ///////////////////////////////////////////////////////////////////////

  //     checking for incoming messages

  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {

    // Message with a good checksum received, dump it.
    Serial.println("Got: ");  // Show on PC for debugging

    PIN = buf[0];   // read Tx PIN number from buffer 0
    if ( PIN == address ) {   //  everything below only runs if PINs match
      Serial.println(" PINs match ") ;

      blank =0;  //  brings display out of standbye with any button pressed

      key = buf[1];  // if PINS match, read key number from buffer 1

 if ( T >= 10 && pause == LOW  || T == 0) {
        T = 10 * buf[2] + buf[3] ;
 }

      Serial.print(" Tx PIN address = ");   
      Serial.println(PIN);
      Serial.print(" key number = ");     
      Serial.println(key);
      Serial.print(" seconds remaining = ");   
      Serial.println(T);
      Serial.print(" Rx PIN address = ");   
      Serial.println(address);
      Serial.println(""); // spaces it out for the monitor

      checkbutton ();    ////////////////////////////////////////////////////////////// decode keys

      Serial.print("time = ");     
      Serial.println(T);
      Serial.print("pause = ");     
      Serial.println(pause);
      Serial.print("key = ");     
      Serial.println(key);
      Serial.print("address = ");     
      Serial.println(address);
      Serial.print("toot = ");     
      Serial.println(toot);
      Serial.print("blank = ");     
      Serial.println(blank);
      Serial.println("");

      if ( blank == 1 ) { 

        T=0;
        pause = 1;
      } // blank the shift reg, reset and stop the clock when in standbye

    } // end of if PINs match
  }//  end of if message received
}  //  end of loop

void checkbutton () {
  switch (key)
  {
  case 68:  // "set 24" and pause ascci  68 key D
    pause=1;     // sets countdown timer , and pauses countdown
    break;     
  case 66:  //set 14 and pause ascci  66 key B
    //sets countdown timer , and pauses countdown
    pause=1;
    break;     
  case 67:  // "set 60 " and run  ascci  67  key C
    // sets countdown timer , and runs timeout
    pause=0;
    break;       
  case 65: // "standby"  ascci   65  key A
    // puts into standby
    pause=1;
    blank=1;
    break;     
  case 57: 
    //  "reset"  sets 24 and runs countdown  ascci  57 key 9
    pause=0;
    break;
  case 53: 
    pause=1; // "  run "  ascii 53 key 5
    break;
  case 48: 
    pause = 0;  // "pause"  ascci 48  key 0
    break;
  case 51: 
    toot = 1;  // "horn"  toots horn for 2 secs  ascci  51 key 3
    break;   
  }  // end of switch
}  // end of checkbutton function
1214  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 02:46:57 am
and part 2 of the Tx:


Code:

 // put our address together
  // read our expansion address
  add3 = digitalRead(SW3); // not using for now, needed to use the pin on the receiver
  // shift it left 3 places
  add3 = add3 << 3;
  add2 = digitalRead(SW2);
  // shift it left 2 places
  add2 = add2 << 2;
  add1 = digitalRead(SW1);
  // shift it left 1 place
  add1 = add1 << 1;
  add0 = digitalRead(SW0);
  // now OR it together
  address = address|add3;
  address = address|add2;
  address = address|add1;
  address = address|add0;
  Serial.println("my address is: ");
  Serial.println(address, BIN);
  msg [0]  = address;

  pinMode(dpin18, INPUT);
  digitalWrite(dpin18, HIGH);
  pinMode(pauseLED, OUTPUT);
  digitalWrite(pauseLED, LOW);      // keep pause LED off
  digitalWrite(ledPin, LOW);                   // pin 13, turn off the LED
  // Serial.begin(9600);                // need for debug monitoring only with FTDI connected via USB to PC
  Serial.println("TX setup");              // for debug only

  // ***********************************************************************
  // Initialise the IO and ISR for VirtualWire
  vw_setup(4000);                       // Bits per sec - had to double from 2000 with 8MHz 3.3V Pro-Mini

}                                            // end of void Setup()

void loop()
{


  if (sleep_count>1000){                      // check if we should go to sleep because of "time" --> Try shorter versions of this
    sleep_count=0;                           // turn it off for when we wake up
    Serial.println("Sleep");               // for debug only
    // set the columns low before sleeping, otherwise Keypad leaves them high and Rows have nothing to pull low.
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    digitalWrite(10, LOW);   
    delay(100);                               // need this?
    enterSleep();                             // call Sleep function to put us out
    //  THE PROGRAM CONTINUEs FROM HERE after waking up in enterSleep()
  }                                           // end of checking to go to sleep

  char key = keypad.getKey();                 // reading the keypad
  if(key)                                     // same as if(key != NO_KEY)- did something change?
  {
     switch (key)
    {
    case 'D':  // "set 24" and pause ascci  68
      T=249;
      pause=1;     // sets countdown timer , and pauses countdown
      break;
    case 'B':  //set 14 and pause ascci  66
      T=149;    //sets countdown timer , and pauses countdown
      pause=1;
      break;
     case 'C':  // "set 60 " and run  ascci  67
      T=609;   // sets countdown timer , and runs timeout
   
       pause=0;
      break;
      case 'A': // "standby"  ascci   65
       // puts into standby
      pause=1;
      blank=1;
      break;
     
    case '9': 
      T=249;   //  "reset"  sets 24 and runs countdown  ascci  57
      pause=0;
      break;
    case '5': 
      pause=1; // "  run "  ascii 53
      break;
    case '0': 
      pause = 0;  // "pause"  ascci 48
      break;
      case '3': 
      toot = 1;  // "horn"  toots horn for 2 secs  ascci  51
      break;
     
        case '#':  // unused keys to be skipped
      skip = 1;
      break;
     
      case '6': 
      skip = 1;
      break;
     
      case '8': 
      skip = 1;
      break;
     
       case '2': 
      skip = 1;
      break;     
     
     
    }


   if ( skip == 0 ) {
     
 // int Ttens = T >> 8;
 //int   Tmod = T & 0xff;
   int Ttens = T/10;
   int Tmod = T%10;
   
    msg[0]= address;
    msg[1]= key;
  //  msg[2] = Ttens;   // seconds remining in countdown tens
 //   msg[3] = Tmod ;  // seconds remining in countdown units
 
msg[2] = 0x12;
msg[3] = 0x34;
 
 
    digitalWrite(ledPin, true);               // Flash a light to show transmitting

    vw_send((uint8_t *)msg, strlen(msg));     // send the character out
    //Serial.println(key);                // for debugging only
    vw_wait_tx();                             // Wait until the whole message is gone
 delay (50);
     digitalWrite(ledPin, false);              // turn off the flash of LED

    sleep_count = 0;                          // reset count up to sleep if transmitted a key press
 }
 skip = 0;
  }                                           // end of if(key) & transmitting a character

  if (T <= 0 ){
    sleep_count = sleep_count+1;
  }               // start counting to go to sleep if not counting down play time

     if (T >= 0 && pause == 1 ) { digitalWrite ( pauseLED, HIGH ) ; }


  if (T >= 0 && pause == 0 ) {

    unsigned long currentMillis = millis();

    if(currentMillis - previousMillis > interval) {
      // save the last time you blinked the LED
      previousMillis = currentMillis;   
      T -- ;
      if ( T== -1 ){
        T = 0 ;
      }
     
       Serial.println(T);
   Serial.println("");
    }
  }
}                                             // end of void loop



1215  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 02:45:04 am
I tried those 2 values. and I get 232 out for T at the Rx end

I will post the code, its rather a mess with all the things I have been trying in my ignorance !

Heres the Tx part 1 :-


Code:


#include <VirtualWire.h>    // Wireless transmitter/receiver library
#include <Keypad.h>         // Matrix Keypad library
#include <avr/sleep.h>      // powerdown library
#include <avr/interrupt.h>  // interrupts library

int SW0 = 14;               // bits to read in unique address - LSB
int SW1 = 15;               // bits to read in unique address
int SW2 = 16;               // bits to read in unique address
int SW3 = 17;               // bits to read in unique address - MSB
int address = 0;            // bits put together afteer reading switches
int add0;
int add1;
int add2;
int add3;
long previousMillis = 0;        // will store last time LED was updated
long interval = 100;           // interval at which to blink (milliseconds)
int T;
int pause=1;
int pauseLED= 19;
int toot;
int blank;
int skip;
// define unused pins
int dpin0 = 0;              // apparently redefined by Serial as Serial Monitor works
int dpin1 = 1;              // apparently redefined by Serial as Serial Monitor works
int pin2 = 2;               // Int0 interrupt pin

int dpin18 = 18;
#define ledPin 13          // activity indicator, use for brief flash when transmit
int sleep_count = 0;      // flag/counter to tell us to go sleep

char msg [4];

const byte ROWS = 4; // Four rows
const byte COLS = 3; // Four columns


char keys[ROWS][COLS] =
{
   {    
    '2','3','A'        }  
  ,  // row 1
  {    
    '5','6','B'        }  
  ,  // row 2
  {    
    '8','9','C'        }  
  ,  // row 3
  {    
    '0','#','D'        }  
  ,  // row 4

};

byte rowPins[ROWS] = {
  6, 5, 4, 3  };  // Keypad uses internal pullups? No externals supplied

byte colPins[COLS] = {
  9, 8, 7 };

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

//***************************************************
// *  Name:        pin2Interrupt, "ISR" to run when interrupted in Sleep Mode
void pin2Interrupt()
{
  /* This brings us back from sleep. */
}

//***************************************************
// *  Name:        enterSleep
void enterSleep()
{
  /* Setup pin2 as an interrupt and attach handler. */
  attachInterrupt(0, pin2Interrupt, LOW);
  delay(50); // need this?
 
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // setting up for sleep ...
  sleep_enable();                       // setting up for sleep ...
  ADCSRA &= ~(1 << ADEN);
  PRR = 0xFF;
   sleep_mode();                         // now goes to Sleep and waits for the interrupt

  /* The program will continue from here after the interrupt. */
  detachInterrupt(0);                
  PRR = 0x00;
    sleep_disable();

  // set all the keypad columns back high so can read keypad presses again
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);
  // digitalWrite(10, HIGH);
  // then go to the void Loop()
}

// ***********************************************************************
// set up the pins as Inputs, Outputs, etc.
void setup()
{

  Serial.begin(9600);
  // pause = 1;

  /* Setup the pin directions, write inputs High to turn on internal pullups */
  pinMode(pin2, INPUT);                 // our sleep interrupt pin
  digitalWrite(pin2, HIGH);

  // define all the unused pins as inputs with internal pullups for lower power state
  pinMode(dpin0, INPUT);                  // apparently redefined by Serial as Serial Monitor works (receiving anyway)
  digitalWrite(dpin0, HIGH);              // apparently redefined by Serial as Serial Monitor works
  pinMode(dpin1, INPUT);                  // apparently redefined by Serial as Serial Monitor works
  digitalWrite(dpin1, HIGH);              // apparently redefined by Serial as Serial Monitor works

  pinMode(SW0, INPUT); // LSB of remote Address
  digitalWrite(SW0, HIGH);
  byte add0 = 0; // read the value of SW0
  pinMode(SW1, INPUT); // LSB+1
  digitalWrite(SW1, HIGH);
  byte add1= 0;
  pinMode(SW2, INPUT);  // LSB+2
  digitalWrite(SW2, HIGH);
  byte add2 = 0;
  pinMode(SW3, INPUT);  // MSB of address
  digitalWrite(SW3, HIGH);
  byte add3 = 0;

 [code]
[/code]
Pages: 1 ... 79 80 [81] 82 83 ... 97