Show Posts
Pages: 1 2 [3] 4 5 ... 8
31  Using Arduino / Programming Questions / Re: Some guidance / advice please on: February 09, 2012, 03:18:09 pm
Not sure how to determine that.  The card/sticker will be attached to the underside of a slot car.  As the car moves over the sensor at any speed, I need to be able to read and decode the code....at least that's the aim.
32  Using Arduino / Programming Questions / Re: Some guidance / advice please on: February 09, 2012, 03:07:32 pm
In the application, the sensor will be fixed and the card will be moving rapidly over the sensor.
33  Using Arduino / Programming Questions / Re: Coping an array. on: February 09, 2012, 01:34:28 pm
If you want to copy from ledEbeneOben to ledEbeneOben_buffer:
Code:
memcpy( ledEbeneOben_buffer, ledEbeneOben, sizeof(ledEbeneOben_buffer) );
or from ledEbeneOben_buffer to ledEbeneOben:
Code:
memcpy( ledEbeneOben, ledEbeneOben_buffer, sizeof(ledEbeneOben_buffer) );
This will be ok as long as both buffers are identical size.
34  Using Arduino / Programming Questions / Some guidance / advice please on: February 09, 2012, 01:21:20 pm
I've hooked up a Photo Reflector ( Photo Reflector SY-CR102 ) to my Arduino Uno 3.  Its connected to analogue 0.  Using a white card with some black stripes on it, I have held the card over the Photo Reflector and moved it back and forth.  I can see that the analogue reading is changing rapidly from anything between 1023 down to 100 counts.

Question is how to I translate this into something useful I can use to read a kind of barcode from?
35  Development / Other Software Development / Re: Timer library: clsTimer on: February 09, 2012, 02:45:56 am
Ok, glad your using it.
36  Development / Other Software Development / Re: Event Library: clsEvent on: February 04, 2012, 04:18:31 am
Modified class removing debug flag and replacing with DEBUG_EVENTS definition and condition compilation check.
37  Development / Other Software Development / Re: Timer library: clsTimer on: February 04, 2012, 04:18:14 am
Modified class removing debug flag and replacing with DEBUG_TIMER definition and condition compilation check.
38  Using Arduino / Microcontrollers / Arduino UNO 3 Digital I/O count on: February 04, 2012, 03:02:01 am
I've looked at the standard "pins_arduino.h" and there are definitions:

NUM_DIGITAL_PINS with a value of 20 and NUM_ANALOG_INPUTS with a value of 6. 

The page for the Arduino Uno says they're are 14 digital I/O and 6 analogue inputs.

I've run a bit of code to query the digital I/O information, and the results I got back are:
Pin: 1, bit: 2, port: 4
Pin: 2, bit: 4, port: 4
Pin: 3, bit: 8, port: 4
Pin: 4, bit: 16, port: 4
Pin: 5, bit: 32, port: 4
Pin: 6, bit: 64, port: 4
Pin: 7, bit: 128, port: 4
Pin: 8, bit: 1, port: 2
Pin: 9, bit: 2, port: 2
Pin: 10, bit: 4, port: 2
Pin: 11, bit: 8, port: 2
Pin: 12, bit: 16, port: 2
Pin: 13, bit: 32, port: 2
Pin: 14, bit: 1, port: 3
Pin: 15, bit: 2, port: 3
Pin: 16, bit: 4, port: 3
Pin: 17, bit: 8, port: 3
Pin: 18, bit: 16, port: 3
Pin: 19, bit: 32, port: 3

I can see from the header that some of the digital pins are also used for analog output.  Is there a function I can call that will tell me if a pin is available for use?

I would like to create a class which enables me to read and write packed bytes to a port, so I can read and write to mutiple digital I/O pins with a single call.  It certainly looks like this is possible from the source.
39  Development / Other Software Development / Re: Event Library: clsEvent on: February 03, 2012, 01:48:05 pm
Sample sketch...

This just waits for a push button to be pressed then turns on an LED.
Code:
#include <clsEvent.h>

#define PUSH_BUTTON 8
#define MY_LED          13

bool pushButton(clsEvent* pEvent) {
  unsigned long uldTime = 0;    
  while( (digitalRead(PUSH_BUTTON)) == LOW ) {
    if ( uldTime == 0 ) {
// Get reference time
      uldTime = millis();    
    } else if ( (millis() - uldTime) > 200 ) {
// Time expired whilst still high
      return true;
    }
  }
  return false;
}

void swithcOnLED(clsEvent* pEvent) {
  digitalWrite(MY_LED, HIGH);
}

void setup() {  
  pinMode(MY_LED,             OUTPUT);
  pinMode(PUSH_BUTTON,    INPUT);
  digitalWrite(PUSH_BUTTON, HIGH);

  new clsEvent("pbTest", pushButton, swithcOnLED, NULL);
}

void loop() {
// Service any events
  clsEvent::serviceEvents();
// Everything else...
}
40  Using Arduino / Networking, Protocols, and Devices / Re: SCADABR with modbus RTU on: February 02, 2012, 03:38:35 pm
What form of modbus are you using rs232 or tcp?  Also what variant, ASCII or rtu?

41  Development / Other Software Development / Re: Event Library: clsEvent on: February 02, 2012, 03:34:16 pm
Will do, have to wait until tomorrow, on iPad atm
42  Using Arduino / Programming Questions / Re: if() and for() structures on: February 02, 2012, 03:27:47 pm
Loop will run indefinitely.  If you want it to stop at 50, try:

Code:
void loop() {
  If ( x++ <= 50 ) {
    Serial.println( x );
    Serial.println( "Hello" );
    delay( 100 );
  }
}
43  Development / Other Software Development / Event Library: clsEvent on: February 02, 2012, 01:57:05 pm
Please find below link and source to an event library:
http://avasig.com/clsEvent.zip

Prototype, clsEvent.h
Code:
/**
 * File:
 *  clsEvent.h
 *  
 * Notes:
 *  This file contains the prototype for the class clsEvent.
 *  
 * Methods:
 *  clsEvent      Class constructor
 *  debug         Enable or disable debugging msgs on serial O/P
 *  getName       Returns the name assigned to this event
 *  serviceEvents Should be called in main loop to service events  
 *
 * Members:
 *  m_pTest       Test callback should return true if event should occur
 *  m_pCallback   Call-back routine to call when event test expression is true
 *  m_pData       Data to associate with this instance
 *  m_pstrName    The name assigned to this event
 *  m_pNext       Next event in Linked-list      
 *            
 * History:
 *  29/01/2012  Created by Simon Platten
 */            
#ifndef EVENT_MANAGER_H
  #define EVENT_MANAGER_H
  
  #include <Arduino.h>
  
  class clsEvent {
  private:
    char*     m_pstrName;
    bool      (*m_pTest)(clsEvent* pEvent);
    void      (*m_pCallback)(clsEvent* pEvent);
    void*     m_pData;
    clsEvent* m_pNext;
      
  public:
    static void debug(bool blnDebug);    
    static void serviceEvents();
  
  public:
    clsEvent(char* pstrName,
             bool (*pTest)(clsEvent* pEvent),              
             void (*pCallback)(clsEvent* pEvent),
             void *pData = NULL);
    char* getName();
  };
#endif

Implementation, clsEvent.cpp
Code:
/**                                                                                 /**
 * File:
 *  clsEvent.cpp
 *  
 * Notes:
 *  This file contains the implementation of the class clsEvent.
 *
 * History:
 *  29/01/2012  Created by Simon Platten
 */  
#include "clsEvent.h"
// Pointer to all events linked list
static clsEvent* pAllEvents = NULL;
static bool blnDebugFlag = false;
/**
 * Event constructor
 *  
 * Paramters:
 *  pstrName,   A description of this event
 *  pTest,      callback routine to test if event should occur
 *  pCallback,  the routine to call when the timer expires
 *  pData,      pointer to data block accessible for this timer  
 */        
clsEvent::clsEvent(char* pstrName,
                   bool (*pTest)(clsEvent* pEvent),              
                   void (*pCallback)(clsEvent* pEvent),
                   void *pData) {
// Configure this event
  m_pstrName = pstrName;
  m_pTest = pTest;
  m_pCallback = pCallback;
  m_pData = pData;
  
  if ( pAllEvents != NULL ) {
// Insert this event into the list of all events
    m_pNext = (clsEvent*)pAllEvents;              
  } else {
// This is the first node in the list, ensure that there is no Next node    
    m_pNext = NULL;
  }
// Insert this timer at the beginning of the linked list    
  pAllEvents = this;                    
}
/**
 * Enable or disable debugging msgs on serial O/P
 */
void clsEvent::debug(bool blnDebug) {
  blnDebugFlag = blnDebug;
}
/**
 * Returns the name assigned to this event
 */
char* clsEvent::getName() {
  return m_pstrName;
}
/**
 * Should be called in main loop to service events
 */  
void clsEvent::serviceEvents() {
  for( clsEvent* pEvent=pAllEvents; pEvent!=NULL;
       pEvent=pEvent->m_pNext ) {
    if ( (*pEvent->m_pTest)(pEvent) == true ) {
      if ( blnDebugFlag == true ) {
        Serial.print(pEvent->getName());
        Serial.println(" is true!");
      }    
      (*pEvent->m_pCallback)(pEvent);
    }      
  }
}

The idea behind this class is simple, create your own event using:
Code:
new clsEvent(pstrName, pTest, pCallback, pData);

pstrName is a text string that describes the event, used only when debugging enabled, to show output on serial port
pTest, is a pointer to a test function, prototype: bool (*pTest)(clsEvent* pEvent)
pCallback, is a pointer to a function to call when the result of pTest is true, prototype:  void (*pCallback)(clsEvent* pEvent)
pData, is an option pointer to your own data structure that you can reference via the pEvent pointer passed to your callback.

I am using this to register a test for a push button, the test routine debounces the button and returns true or false, my call back routine then performs an action.

Forgot to mention, you will also need to call the static routine:
Code:
clsEvent::serviceEvents();
From within you loop.
44  Using Arduino / Programming Questions / Re: Debounce routine works once only on: February 02, 2012, 01:43:04 pm
Modified debounceDI routine:
Code:
bool clsApp::debounceDI(uint8_t ud8DI, int intState, unsigned long uldMS) {
  unsigned long uldTime = 0;
  while( (digitalRead(ud8DI)) == intState ) {
    if ( uldTime == 0 ) {
// Get reference time
      uldTime = millis();    
    } else if ( (millis() - uldTime) > uldMS ) {
// Time expired whilst still high
      return true;
    }
  }
  return false;
}

This one works fine, I think that what was happening before is that arduino was probably running out of memory probably due to fragmentation due to the creation of the timer object in the function.

Thank you to those that gave assistance.
45  Using Arduino / Programming Questions / Re: Debounce routine works once only on: February 01, 2012, 04:56:57 pm
Yes, I did edit the post realising my error.  As mentioned above I will try modifying the Debounce, implementing a static instance of the timer
Pages: 1 2 [3] 4 5 ... 8