Show Posts
Pages: 1 ... 423 424 [425] 426 427 ... 579
6361  Using Arduino / Programming Questions / Re: How does serial handle data. on: May 19, 2011, 03:21:24 am
That's one hell of an if/else rats nest Mike, the variable you're testing against seems to have contiguous values which probably means an array or two can remove all the crap.

Actually, don't all those blocks do the same thing?

Can you spell out exactly what is supposed to happen?

Serial characters can't be received "at the same time" they appear one after the other.

Quote
Its part of a musical instrument and I need to make sure the solenoids are in time.
By directly manipulating the ports, but you shouldn't have to, two digitalWrites() in a row will appear to be simultaneous to a human. Even if there's a serial character in between.
______
Rob
 
6362  Community / Exhibition / Gallery / Re: Greenhouse automation on: May 19, 2011, 03:08:13 am
I think I've trimmed some more fat
Code:
  byte stats;
  byte previousstats;
  
   #define TEMP_RED_BIT B00000001
   #define TEMP_GREEN_BIT B00000010
   #define HUMID_RED_BIT B00000100
   #define HUMID_GREEN_BIT B00001000
   #define MOIST_RED_BIT B00010000
   #define MOIST_GREEN_BIT B00100000
  
  
  stats = 0;
  if((temperature < 22) || (temperature > 28)) {
    stats |= TEMP_GREEN_BIT   // green on
  } else {
    stats |= TEMP_RED_BIT;    // red on
  }
  //Humidity
  if((humidity < 60) || (humidity > 80)) {
    stats |= HUMID_GREEN_BIT   // green on
  } else {
    stats |= HUMID_RED_BIT;    // red on
  }
  //Soil
  if((moisture_val < 850) || (moisture_val > 1000)) {
    stats |= MOIST_GREEN_BIT   // green on
  } else {
    stats |= MOIST_RED_BIT;    // red on
  }
 
  ////Checks if update to control panel is needed
  if(stats != previousstats) {
digitalWrite(latch, LOW);
shiftOut(data, clock, MSBFIRST, stats);  // don't need the led() function any more
digitalWrite(latch, HIGH);
        previousstats = stats;
  }
  

You could also use the same arrangement but change the #defines to bit numbers and have bitWrites() instead of the &= and |= with bit patterns.


______
Rob
6363  Using Arduino / Project Guidance / Re: Designed an Attiny "BBB" type board, need input on: May 19, 2011, 02:45:52 am
It's starting to look good.

The 10k pull up resistor is a tad close to the DIP socket.

The holes for the DC barrel jack, they either have to be slots or WAY bigger than that.

2k2 is too large for the LED, although that doesn't affect the PCB layout.

______
Rob
6364  Using Arduino / Programming Questions / Re: storing int in byte-variable on: May 19, 2011, 02:06:42 am
Well cut of me legs and call me shorty, thanks AWOL, I learn something new every day, I was sure it would clobber a byte.

I just tried this

Code:
  byte x;
 int y = 1234;
 x = y; 

with -Wall, not even a warning. However

Code:
  byte x;
 int y = 1234;
 x = 1234; 

Gives "large integer implicitly truncated to unsigned type"


______
Rob
6365  Using Arduino / Programming Questions / Re: storing int in byte-variable on: May 19, 2011, 01:38:29 am
Firstly the compiler should throw an error.

If you force the issue you will clobber a byte on one side of the variable.

Is there a reason to do this?

______
Rob
6366  Community / Exhibition / Gallery / Re: Greenhouse automation on: May 19, 2011, 01:33:41 am
Code:
/////Light trigger
  if((0 <= hour(t)) && (18 > hour(t))) { ///Between which hours on
    lightstatus = 1;
  }
  if((18 <= hour(t)) && (24 >= hour(t))) { ///Between which hours off
    lightstatus = 0;
  }

could be

Code:
/////Light trigger
  lightstatus = hour(t) < 18 ? 1 : 0;


Code:
if(stats != previousstats) {
This compares the addresses of the two arrays, they will never be ==

As they are arrays of binary numbers you have to use memcmp() to compare them.

Then you can use memcpy() to move one into the other.

______
Rob
6367  Using Arduino / Project Guidance / Re: Coin Counter on: May 19, 2011, 01:16:08 am
No guarantees but I'm happy to help.

As there are much better coders than me here I take some comfort from the fact that no one has pinged me on the code yet, or maybe they just haven't noticed the thread smiley

______
Rob
6368  Using Arduino / Project Guidance / Re: 12 Volt Trigger on: May 19, 2011, 12:29:48 am
Quote
How and where in the sketch does this command need to be?
Normally in the loop() function.

Code:
void loop () {
   if (digitalRead(triggerPin) == LOW) { // assumes the opto is wired to pull pin low
       // sequence code here
   }
}

However if you only want this to run once you can put it in the setup() function.

Quote
Then output to the next pin (cue 2) at a user defined timing delay with a 1 second pulse so forth
I'll get into trouble for using delay() here but for this simple application I would suggest something like this.

Code:
void loop () {
   if (digitalRead(triggerPin) == LOW) { 
       digitalWrite (seq1Pin, HIGH)
       delay (1000);
       digitalWrite (seq1Pin, LOW)

       digitalWrite (seq2Pin, HIGH)
       delay (1000);
       digitalWrite (seq2Pin, LOW)

       digitalWrite (seq3Pin, HIGH)
       delay (1000);
       digitalWrite (seq4Pin, LOW)
   }
   while(1);  // if you don't want this to run a second time, OR put this in setup()
}

If you have a LOT of sequences (did you say 12?) then an array would be better.

Code:
byte pins [] = {2, 3, 4, 6, 8, 9, 10, 11, 18, 23, 44, 51};  // whatever pins you are using
const int N_PINS = sizeof (pins) / sizeof (pins[0]);
 
void loop () {
   if (digitalRead(triggerPin) == LOW) {
       for (int i = 0; i < N_PINS; i++) {
          digitalWrite (pins[i], HIGH)
          delay (1000);
          digitalWrite (pins[i], LOW)
      }
}

Quote
how would the optoisolator be connected to the input pin on the arduino for it to read the input?
Emitter to GND, collector through a resistor to VCC (the resistor can be omitted if you use the Arduino's inbuilt pull up resistor). Collector to Arduino pin.

Quote
Will my 12 volt source need a resistor of some sort so that the current doesn't destroy the optoisolator?
Yes, value depends on the opto's LED but about 1k should be OK.

______
Rob
6369  Using Arduino / LEDs and Multiplexing / Re: programing and wiring 2 Multiplexer / demultiplexer with arduino on: May 18, 2011, 09:17:07 pm
You do realize that you can't use 4067s for outputs unless you only need one output on at a time, it's been stated a couple of times but I'm not sure you've pick up on it.

BTW, your picture links to your C drive, that ain't gonna work smiley
______
Rob
6370  Community / Products and Services / Re: Schematice of all the bricks on: May 18, 2011, 09:08:41 pm
Have a look at Terry King's site

http://yourduino.com/

Or get in touch with him. Last I heard he was trying to document all the bricks.

______
Rob

6371  Using Arduino / Project Guidance / Re: Designed an Attiny "BBB" type board, need input on: May 18, 2011, 08:11:34 pm
Quote
Any thoughts on trace width for signals and for the VCC/GND lines?
For such a small board with only one active component I would say 20-30mil would be more than enough.

Google "pcb trace width calculator"

Quote
I think I'm going to change it to a single 7 or 8 pin connector if I can make it route nicely though.
I can't see why you're having trouble realigning the headers, there's only 5 traces on the whole board smiley If they are in a row the board will plug in directly to a BB. As they are I don't see how it can plug in at all (I'll have to drag out a BB and have a look).

______
Rob
6372  Community / Exhibition / Gallery / Re: Greenhouse automation on: May 18, 2011, 12:47:35 am
Hi SpencerH,

Do you really have 3 phase power or are the three "mains" wired the same active.

6A @ 240V means huge motors, are they really that big?

I gather they are DPDT relays and the "to CP" contacts are just to show they are working with the other pole doing the pump/whatever control.

______
Rob
6373  Using Arduino / Project Guidance / Re: Designed an Attiny "BBB" type board, need input on: May 18, 2011, 12:24:32 am
Why not put the two breadboard power pins in line with the IO pins? That way the whole thing plugs straight onto a breadboard. As it is you'll have to run flying wires from one or the other.

______
Rob
6374  Community / Bar Sport / Re: My electric blanket doesn't work ... on: May 17, 2011, 10:24:28 pm
Yes, in Aus you can pick your climate of choice.

Tassie, mostly cool/cold, green babbling brooks, much like England.
Lower states, pretty cold in winter to very hot (40+) in summer.
High country, more snow than Switzerland in winter, mild to cold in summer (still snow in summer on occasion).
The outback, varies between really cold and boiling hot -10 nights to 45+ (even 50+ in places) days.
Upper states (tropics) same temp all year round (approx 30-35 days) but humidity changes from dry to very humid.

_____
Rob
6375  Community / Bar Sport / Re: Employment for Arduinoites on: May 17, 2011, 10:01:54 pm
No sooner have I spoken than we get this post

http://arduino.cc/forum/index.php/topic,61488.0/topicseen.html

______
Rob
Pages: 1 ... 423 424 [425] 426 427 ... 579