Show Posts
Pages: 1 ... 414 415 [416] 417 418 ... 593
6226  Using Arduino / Project Guidance / Re: Up down counter issues on: August 08, 2011, 06:40:32 pm
Must have been the beer smiley

Here's a version that compiles

Code:
//   G F + A B
//   | | | | |   -> pins and segments they control
//   ---------
//  F|   A   |B
//   |---G---|   -> segments
//  E|   D   |C
//   ---------
//   | | | | |   -> pins and segments they control
//   E D + C DP

// Segments that make each number when lit:
// 0 => ABCDEF
// 1 => BC
// 2 => ABDEG
// 3 => ABCDG
// 4 => BCFG
// 5 => ACDFG
// 6 => ACDEFG
// 7 => ABC
// 8 => ABCDEFG
// 9 => ABCDFG

// Arduino digital pins used to light up
// corresponding segments on the LED display
#define A 2
#define B 3
#define C 4
#define D 5
#define E 6
#define F 7
#define G 8
#define GND1 9
#define GND2 10

// Pushbutton connected to pin 11
#define BUTTON 11

// Common anode;
// on when pin is low
// and off when pin is high
#define ON HIGH
#define OFF LOW

int count = 10; // current display count
int val = 0;   // digital input from button

//             A B C D E F G
int pins [] = {2,3,4,5,6,7,8}; // the Arduino pins that drive the segments

byte segments[] = { // you set the correct bits B7 = G, B0 = A
B00000000, // 0
B00110011, // 1
B00110011, // 2
B00110011, // 3
B00110011, // 4
B00110011, // 5
B00110011, // 6
B00110011, // 7
B00110011, // 8
B00110011,      // 9
B00110011, // B
B00110011, // C
B00110011, // D
B00110011, // E
B00110011 // F
};


void setup() {
  for (int i = 0; i < 7; i++)
pinMode(pins[i], OUTPUT);
 
  pinMode(GND1, OUTPUT);
  pinMode(GND2, OUTPUT);
  pinMode(BUTTON, INPUT);
 
}

void loop() {
  val = digitalRead(BUTTON);
  if (val == HIGH) {
    count--;
    delay(300);
set_segments (count);
  }
}

void set_segments (byte val) {
for (int seg = 0; seg < 7; seg++) {
digitalWrite(pins[seg], val & 1);
val >>= 1;
}
}


______
Rob

6227  Using Arduino / Project Guidance / Re: Up down counter issues on: August 08, 2011, 11:40:52 am
Have a look back at reply #6, I think my set_segments() function (plus the "segments" array) does the same as your segmentdisplay() function.

Just add another 6 entries to segmenst[] as it currently only does 0-9.

______
Rob
6228  Using Arduino / Project Guidance / Re: memory for digital programming on: August 08, 2011, 11:22:25 am
Here's an example of some code that should give you a start (only for one sensor)

Code:
#define INVALID_VALUE 0xFFFF
#define N_READINGS 21
#define SOME_VALUE 500
#define SOME_PIN 10

unsigned int sensor_data[N_READINGS];  // ring buffer for one sensor
int data_index = 0;
static unsigned long last_millis = millis();

void setup () {

   Serial.begin (9600);
   pinMode (SOME_PIN, INPUT);
   digitalWrite (SOME_PIN, 1);  // set internal pullup resistor
   
   // fill the ring buffer with a value that won't trigger the task
   for (int i = 0; i < N_READINGS; i++)
       sensor_data[INVALID_VALUE];
}

boolean time_to_take_reading() {
   static unsigned long this_millis;
   // some code that decides if it's time to take a reading
   // for testing just return true every second
   this_millis = millis();
   if (this_millis - last_millis > 1000) {
      last_millis = this_millis;
      return true;
   }
   return false;
}

int getReading() {
   // some code that gets a reading from the sensor
   // for testing return either 0 or 1000 according to a digital input value
   return digitalRead (SOME_PIN) * 1000;
}

void performTask() {
// some code that performs the task
Serial.println ("task");
}

void loop () {
   boolean perform_task;

   if (time_to_take_reading()) {

     sensor_data [data_index++] = getReading();  // get a new reading and store at the head of the ring buffer
   if (data_index >= N_READINGS) data_index = 0; // reset buffer index if necessary
     
   perform_task = true;    // assume we will perform the task
   
   // scan the ring buffer
   // if any value in the buffer is greater than SOME_VALUE then reset the the "perform_task" flag
   for (int i = 0; i < N_READINGS; i++) {
              if (sensor_data[i] > SOME_VALUE)
      perform_task = false;
   }
          // if we got through the last loop without resetting the flag then all values
   // were < SOME_VALUE so we perform the task
   if (perform_task)
       performTask();
    }
}

For multiple sensors you probably should create an array of structures or maybe just more arrays. But we'll cross that bridge if you get to it.

As written it should print "task" if you hold pin 10 low for 21 seconds.

______
Rob
6229  Using Arduino / Project Guidance / Re: Do I need pull ups or buffers maybe? on: August 08, 2011, 05:11:04 am
By "Hyperterminal" do you mean running on the same computer over the same USB link as Serial monitor is?

Also, what's the "external device"?

______
Rob
6230  Using Arduino / Sensors / Re: new thermocouple interface: MAX31855 on: August 08, 2011, 01:57:41 am
Quote
only use with 3.3V
Yep, I didn't spot that.

Thanks for the source code, I've grabbed it for when I start using the chip. Is it the same as the 6675 software wise?

______
Rob
6231  Using Arduino / Programming Questions / Re: Reading in ASCII through serial on: August 08, 2011, 01:24:21 am
If you have a byte == 6D and the next FC and they are really two halves of a 16-bit int then yes you just combine them, like this

Code:
unsigned int new_val;
new_val = (buffer[1] << 8) + buffer[2];

(Assuming the value is supposed to be 6DFC, on some systems it should be FC6D, in which case you swap the 1 and 2 in the above example.)

Now new_val is a 16-bit integer and you can do with it what you will.

______
Rob
6232  Using Arduino / Project Guidance / Re: Up down counter issues on: August 08, 2011, 01:17:05 am
The code is OK for a start, but the segmentdisplay() func is about 150 lines long and as far as I can see it does the same as my 6-line function.

You've made a start by having pin numbers in an array and using a few loops to set pins, I'd see if you can reduce it even more.

______
Rob
6233  Topics / Home Automation and Networked Objects / Re: Home Automation controlled with Android App. on: August 08, 2011, 01:08:51 am
That's great, I can see some Android in my future smiley

______
Rob
6234  Using Arduino / Project Guidance / Re: Up down counter issues on: August 07, 2011, 06:57:20 pm
No not Fosters although I used to drink that when I was in England.

I haven't bought normal beer for about 10 years, the last "slab" (24 pack) I got was XXXX (A Queensland beer) for $35 up in the Kimberley (northern tropics). That was so expensive to me at the time I started making home brew and have done so ever since.



So why do Queenslanders call their state beer XXXX, because they can't spell beer. smiley

______
Rob

6235  Using Arduino / Project Guidance / Re: How to connect multiple 7 segment display to arduino..?? on: August 07, 2011, 10:48:37 am
The right-hand side of that circuit is a standard multiplexing setup. You could drive that in any one of a dozen ways.

1) Direct from an Arduino
2) Using shift registers
3) Using a driver chip like the AS1108

OK so that's only 3, but there are others and variations of the above.

What are you trying to achieve? How bright do the LEDs have to be?

______
Rob
6236  Using Arduino / Programming Questions / Re: Reading in ASCII through serial on: August 07, 2011, 10:37:17 am
Quote
the ASCII output for the IMU in the serial program looks like this:
The above isn't ASCII though so I would think it's more a case of "why are there any TABs at all?" rather than "where have all the TABs gone?"

buffer should probably be "unsigned char" or "byte".

______
Rob
6237  Using Arduino / LEDs and Multiplexing / Re: 595 & 4021 multiplexing on: August 07, 2011, 05:49:48 am
Quote
I don`t have to push any button, and I get this.
It looks like the data is essentially random, you should get all 1s or 0s. Are you sure the SR is connected correctly?

______
Rob
6238  Using Arduino / LEDs and Multiplexing / Re: 595 & 4021 multiplexing on: August 07, 2011, 05:45:44 am
That code prints the raw value then several chars from an array.

So what numbers/characters are you seeing?

Are you sure the SR is connected correctly?

OK, crossed posts. I'll have a think.

______
Rob
6239  Using Arduino / LEDs and Multiplexing / Re: 595 & 4021 multiplexing on: August 07, 2011, 04:59:26 am
I can't find that "What is pressed" code, can you post it here.

How are you sending the data to the serial monitor?

If you are doing Serial.print (x) and x = B00000100 then you won't see anything because B00000100 == 4 and that's not a printable character.

Try Serial.print (x,HEX) or Serial.print (x,BIN)

______
Rob
6240  Using Arduino / Programming Questions / Re: Reading in ASCII through serial on: August 06, 2011, 11:20:48 pm
Quote
i just looped it which (i think) will display each value of the buffer in sequence:
That's what I meant by

Quote
you have to scan the array and send each byte with

print(buffer[index],HEX);

That looks like sign extension to me. Is buffer[] still an array of char, or did you change it to long?

If we ignore that, the first two "packets" have

Code:
A TAB C5 1 E7 1 22 1 F5 1 E8 1 EC 1 EC Z
A TAB BE 1 E7 1 21 1 F4 1 E7 1 EC 1 EA Z

or maybe

Code:
A TAB C5 1E7 122 1F5 1E8 1EC 1EC Z
A TAB BE 1E7 121 1F4 1E7 1EC 1EA Z

and in decimal

Code:
A TAB 199 487 122 501 488 492 492 Z
A TAB 190 487 121 500 487 492 490 Z

Do those numbers make sense to you?

______
Rob



Pages: 1 ... 414 415 [416] 417 418 ... 593