Show Posts
Pages: 1 [2]
16  Forum 2005-2010 (read only) / Troubleshooting / GSWA - Example 07 - P69 - variable not working on: January 07, 2011, 03:29:58 pm
Platform: WinXP / Arduino UNO
Sketch: (see below) An edited Example 07 from Getting Started With Arduino.

I'm trying to find a way to make the LED at Pin 9 present a wider scope of intensity depending on recent exposure feedback from the LDR. So I've been setting up variables that might be helpful for something like that.

For some reason, my brightness variable keeps coming up zero.
A manual calculation quickly shows we're not in the ballpark for what brightness should be. I double-checked with a spreadsheet of outgoing variables. (See highlighting for quick reference.)

It compiles, so it's probably not a syntax error. I'm guessing it has something to do with 'int'. Can someone explain to me what's going on with that value?

Example serial data, pinout and sketch follow for reference.

Cheers


Example Values - Serial Port Monitor:
Code:
val = 203 | ravgval = 181 | hval = 203 | intensity = 50 | brightness = 0 | thisTime = 5154
val = 207 | ravgval = 193 | hval = 208 | intensity = 51 | [glow]brightness = 0[/glow] | thisTime = 5366
val = 202 | ravgval = 194 | hval = 208 | intensity = 50 | [glow]brightness = 0[/glow] | thisTime = 5236
val = 204 | ravgval = 194 | hval = 208 | intensity = 51 | [glow]brightness = 0[/glow] | thisTime = 5296
val = 131 | ravgval = 175 | hval = 208 | intensity = 32 | brightness = 0 | thisTime = 5008
val = 129 | ravgval = 136 | hval = 188 | intensity = 32 | brightness = 0 | thisTime = 5158
val = 128 | ravgval = 127 | hval = 168 | intensity = 32 | brightness = 0 | thisTime = 5146
val = 127 | ravgval = 126 | hval = 168 | intensity = 31 | brightness = 0 | thisTime = 5104
val = 127 | ravgval = 126 | hval = 168 | intensity = 31 | brightness = 0 | thisTime = 5076
val = 126 | ravgval = 125 | hval = 168 | intensity = 31 | brightness = 0 | thisTime = 5052
val = 126 | ravgval = 125 | hval = 168 | intensity = 31 | brightness = 0 | thisTime = 5058
val = 131 | ravgval = 125 | hval = 168 | intensity = 32 | brightness = 0 | thisTime = 5096
Board Pinout:


Sketch:
Code:
// Example 06A: Blink LED at a rate specified by the value of the analogue input.

#define LED 13 // The pin for the LED
#define LED2 9 // The pin for the LED

int val = 0; // Variable used to store the value coming from the sensor.
int hval = 0; // Keep tabs of the highest value since the last delayTime.
int ravgval = 0; // Keep rolling average.
int intensity = 0; // Buffered val
[glow]int brightness = 0;[/glow] // Calculated brightness value
int delayTime = 5000; // Five seconds in milliseconds.
int thisTime = 0; // A counter to compare with delayTime.

void setup() {
  pinMode(LED, OUTPUT); // LED is an OUTPUT.
  pinMode(LED2, OUTPUT); // LED2 is an OUTPUT.
  
  // Note: Analogue pins are automatically set as inputs.
  
}

void loop(){
  val = analogRead(0); // Read the value from the sensor.
  ravgval = ((14*ravgval)+val)/15; // Mock Rolling Average.
  if(val > hval){
    hval = val;
  }
  intensity = val/4; // analog value transformed to variable within writable parameters
  [glow]brightness = (intensity/254)*hval;[/glow]
  
  digitalWrite(LED, HIGH); // Turn LED on.
  analogWrite(LED2, intensity); // Turn LED2 on.
  
  delay(val); // Stop the program for some time.
  thisTime = thisTime + val; // Add val to current delayTime.
  
  digitalWrite(13, LOW); // Turn LED off.

  delay(val); // Stop the program for some time.
  thisTime = thisTime + val; // Add val to current delayTime.
  
  if (thisTime > delayTime){
  // Write to serial port every time thisTime is greater than delayTime.
    Serial.begin(9600);
    Serial.print("val = ");
    Serial.print(val);
    Serial.print(" | ravgval = ");
    Serial.print(ravgval);
    Serial.print(" | hval = ");
    Serial.print(hval);
    Serial.print(" | intensity = ");
    Serial.print(intensity);
    Serial.print(" | brightness = ");
    Serial.print(brightness);
    Serial.print(" | thisTime = ");
    Serial.println(thisTime);
    thisTime = 0; // Reset our counter.
    if (hval > val + 50){
    hval = hval - 20; // Reduce hval incrementally.
    }
  }

}
17  Forum 2005-2010 (read only) / Troubleshooting / Re: UNO - Headers on Digital Side - Intentional? on: January 22, 2011, 12:12:03 am
retrolefty, Grumpy_Mike,

Thanks for your replies. These are both excellent workarounds.
I admit, until I get a drill press, I'm likely to go with the offset header fix.

Again, thank you.

18  Forum 2005-2010 (read only) / Troubleshooting / Re: UNO - Headers on Digital Side - Intentional? on: January 20, 2011, 03:34:31 pm
Thanks, pluggy, retrolefty.

After browsing around a little, I found this blurb at this page:
Quote
Making Shields

If you'd like to make your own shield, you may want to start with the Eagle files for an existing shield. Note that the space between pins 7 and 8 is not the standard 0.1".
The same is true for all the arduino boards, new and old. I don't know what else to think, so I'm coining a new phrase:

Commons-proprietary - adj. - a small non-standard intentional design flaw made in open-source hardware created for the sole purpose of growing an economy around the same hardware.

Usage: "Does Arduino use commons-proprietary hardware?"

Whether that original 'brain fart' was intentional or not, Arduino certainly has built a thriving community of small and growing businesses. That's a good thing, right?

Are there any suggested workarounds other than wire leads from the arduino pin sockets and then soldered to the perf board if you're using something small like this?

19  Forum 2005-2010 (read only) / Troubleshooting / UNO - Headers on Digital Side - Intentional? on: January 20, 2011, 11:25:39 am
I've been toying with the UNO, and decided to try a perf board with a header. When I tried to match them up across the length of the arduino with the result showing in the image below. I've highlighted the problem, showing how the pins in green don't match the holes in red in an attempt to use a header across the entire array.  A standard header does match up with one pin fitting loose in the gap between the power and analog arrays.

I cannot believe digital array would be intentionally hampered, but I'm new to this, so I have to ask. Is there supposed to be a gap that disallows the use of a standard header and perf board? I got this one from NKC Electronics.

Should I ask for a replacement?

Pages: 1 [2]