Show Posts
Pages: 1 ... 10 11 [12]
166  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Arduino and OBD II diagnostic port on: December 02, 2009, 09:20:48 am
Check this page out.

http://code.google.com/p/opengauge/wiki/OBDuinoInterface
167  Forum 2005-2010 (read only) / Syntax & Programs / Re: Numbers + Random on: December 03, 2009, 03:25:31 pm
Ok. So pretty much it's for no programming significance other than to make the code easier to read if the numbers have alternate meaning to the viewer.

Thanks.....
168  Forum 2005-2010 (read only) / Syntax & Programs / Numbers + Random on: December 02, 2009, 03:29:51 pm
So.... i have seen quite a few programs on here that do a wide variety of things in the last month or so i have been playing with the arduino and scavenging all the information i can get about kewl projects i may be interesting in putting together.

One thing i can't see the difference in is people who do the number add method instead of just typing the number.

for example, whats the difference in...

random (255);

or

random ((120) + 135);

Does it really matter? i have seen quite a few people who do this addition method but normally it seems it would be easier just to put what you want in there and continue on......i dunno maybe i'm just thick.
 
:-/ i'm confused.....
169  Forum 2005-2010 (read only) / Syntax & Programs / Re: moving a servo and fading leds, a newbies prob on: November 29, 2009, 11:21:21 pm
I am fairly new to this whole game too but it looks to me like the highlighted bracket shouldn't be there. Just my 2 pennies....

Code:
for (pulsewidth=255; pulsewidth >= 0; pulsewidth--){  
   analogWrite(led, pulsewidth);  
   delay(time);  
 }  

[glow]{[/glow]  if( wait == 0 ) {
       posHdest = random(70,110);  // move had between 70-110 degrees
       wait = random(150,450);     // between 1.5 secs & 4.5 secs
   }
170  Forum 2005-2010 (read only) / Syntax & Programs / Re: first program, could probably be better..... on: October 18, 2009, 10:31:23 pm
awesome.

 Those are the kind of things you don't get off the reference page on the arduino site. (Which has been invaluable along with this forum the last few days)

Thanks for your thoughts, i will change those around, i still have to expand it a bit to run all the LED's i want to throw in there so i may go ahead and try to define the Fade variable too.

Thanks for your help.
171  Forum 2005-2010 (read only) / Syntax & Programs / Re: first program, could probably be better..... on: October 18, 2009, 10:13:11 pm
what changes by me defineing something as a variable or a contant other than the obvious?

i have been going off of examples found on the web and modeling them for my purposes and have seen the 'const int' and '#define' but don't really understand what the true difference would be.
172  Forum 2005-2010 (read only) / Syntax & Programs / first program, could probably be better..... on: October 18, 2009, 09:24:36 pm
So i just got my first Arduino Board in the other day and i have been playing. I got the protoshield with it from adafruit and so far i have been having a lot of fun with it. I wrote my first program this morning that will eventually turn into a project on my truck. It will control some LED's behind the door handles on my truck.

It's going to be one of those 'just because' projects but i think it will look cool.

Anyway, i would really apreciate it if you could give me some opinons on my coding, there may be a more elegant way to do what i want... but my coding expierence is limited to the last 3 or 4 days so this is what i came up with.

Code:


/* This program is a rough draft of one that will eventually power 6 LED's
that will fade in and out when a vehicle alarm system is armed and when
the vehicle's interior lights come on it will stop the Blue pulse and fade
into a green LED

The LED's are the RGB ones available from adafruit industries. */

int Blue = 6; //Just two LEDs for testing
int Green = 5;

int Pwr = 4; //using two digital pins for power to clean up the wiring on the breadboard
int Pwr2 = 8;

int button = 11; //button to simulate alarm system's 'Ground when armed'
int input2 = 12; //button to simulate trucks interior lighting

int pullUp = 1; //Pull up pins for buttons
int pullUp2 = 0;

void setup () {
  
pinMode (Blue, OUTPUT); //Just two LEDs for testing
pinMode (Green, OUTPUT);
digitalWrite (Blue, HIGH);
digitalWrite (Green, HIGH);

pinMode (Pwr, OUTPUT);//using two digital pins for power to clean up the wiring on the breadboard
pinMode (Pwr2, OUTPUT);
digitalWrite (Pwr, HIGH);
digitalWrite (Pwr2, HIGH);

pinMode (button, INPUT);  //button to simulate alarm system's 'Ground when armed'
pinMode (input2, INPUT);  //button to simulate trucks interior lighting

pinMode (pullUp, INPUT); //Pull up pins for buttons
pinMode (pullUp2, INPUT);
digitalWrite (pullUp, HIGH);
digitalWrite (pullUp2, HIGH);

}

void loop () {
  
int btInput = digitalRead(button); //Check Buttons
int input2st = digitalRead(input2);

if (btInput == LOW) { //if alarm is armed go to blue fade cycle
    alarmFade ();
    
}

else if (input2st  == LOW) { //if dome lights are on go to turn green LED
  domeLight ();
  
}
}


void alarmFade () {
  
    for(int fadeValueB = 255 ; fadeValueB >=0; fadeValueB-=4) { // fade in from off to on
    analogWrite(Blue, fadeValueB); //write to Blue LED pin      
    delay(50);   //Slow Fade
  }

  int input2st = digitalRead(input2); //Check dome light pin in case of a change

  if (input2st  == LOW) { //if dome light is on go to proper loop
  domeLight ();
  
  }
  
  for(int fadeValue = 0 ; fadeValue <=255 ; fadeValue +=5) { // fade out from on to off
    analogWrite(Blue, fadeValue);  //write to Blue LED pin  
    delay(40); //Slow Fade                          
  }
  
  input2st = digitalRead(input2); //Check dome light pin in case of a change
  
  if (input2st  == LOW) {  //if dome light is on go to proper loop
  domeLight ();
  
  }
  
  delay (1500); //pause with LED off for 1.5 seconds
  
  input2st = digitalRead(input2); //Check dome light pin in case of a change
  
  if (input2st  == LOW) { //if dome light is on go to proper loop
  domeLight ();
  
  }
}

void domeLight () {
  
  int btInput = digitalRead(button);  //Check buttons for a change
  int input2st = digitalRead(input2);
 
  if (btInput == HIGH && input2st == LOW){ //if alarm is off and dome light is on turn on green led
    for(int fadeValueG = 255; fadeValueG >=0; fadeValueG -=5) { // fade in from off to on
    analogWrite(Green, fadeValueG);  //write to Green LED pin          
    delay(30);  //Fade
    }
   while (btInput == HIGH && input2st == LOW) { //maintain the Green LED being on until either th alarm is armed or the dome light turns off
  
     digitalWrite (Green, LOW);
    
   btInput = digitalRead(button);
   input2st = digitalRead(input2);
    
   }
 
    for(int fadeValueG = 0; fadeValueG <=255 ; fadeValueG +=5) { //Fade out from on to off
    analogWrite(Green, fadeValueG); //   write to Green LED pin  
    delay(30);//Fade
   }
  }
    
  }  
173  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: PLEASE distribute the software via TORRENT option on: December 01, 2009, 11:25:14 pm
I am downloading now to seed your torrents. I think it's a grand idea. Most people default to 'illegal' when they think torrent but i use them all the time for things even as simple as sharing family photos. Things move sooo much faster when you have a few peers.
174  Forum 2005-2010 (read only) / Interfacing / Re: question and suggestion on: July 31, 2010, 02:02:33 pm
that diagram was build more so for guys who were curious how i wired it more than what was happening in. I just posted it because it was available. It works on but the leds seem to flicker sometimes and i think the signal not being a good square wave is why.

The wiring diagram is of a shield i built from a bread board to tie into.





as far as the diagram goes.

the 6 vertical resistors are tied to the Base of each transistor.

the three transistors on the left tie to the front door handles and interior led's. the three on the right use the other resistors on the board to tie to the rear door handle led's.
175  Forum 2005-2010 (read only) / Interfacing / Re: question and suggestion on: July 31, 2010, 12:46:04 pm
Quote
if ( digitalRead (alarmIn) == HIGH && alarmOffCount == 0 ) {
  alarmOffCount = 1;
  ledFade (fr, fb, fg, rr, rg, rb, 35, .5, 5); // white fade when truck is unlocked
}

while (digitalRead (intlights) == LOW && digitalRead (alarmIn) == HIGH){ //code for interior lights to change colors selected by 5K pot

totalValue = 0; //reset variables at beginning of loop
trueValue = 0;

 for (int i=1; i<=50 ; i++){ //take 50 readings from Analog Input pin
 trueValue = analogRead(colorIn);
 totalValue = trueValue + totalValue;
 sampleTotal = i;
 }

colorValue = totalValue/sampleTotal; //get average of 50 readings pulled in from loop
      
Serial.println(colorValue); // Print average color value to serial port

intLights (0, 175, 0, rr, 0, fr); // takes a value from the pot (0-1023) and uses that value to change the colors on the led
intLights (165, 345, rr, rb, fr, fb);
intLights (335, 515, rb, rg, fb, fg);
intLights (505, 685, rg, rr, fg, fr);
intLights (675, 855, 0, rb, 0, fb);
intLights (845, 1015, 0, rg, 0, fg);

 }


while ( digitalRead (alarmIn) == LOW ) { // While viper is armed pin holds to low and the 4 color fade cycle repeats 100 times

alarmOffCount = 0;

for ( repeatCount=1 ; repeatCount<100 ; repeatCount++ ) {
ledFade (fr, 0, 0, rr, 0, 0, 50, 2, 5); //red fade
ledFade (0, fg, 0, 0, rg, 0, 30, .5, 5); //green fade
ledFade (0, 0, fb, 0, 0, rb, 30, 1, 5); //blue fade
ledFade (fr, fb, fg, rr, rg, rb, 30, .5, 5); // white fade
  
    if ( digitalRead (alarmIn) == HIGH ) {
    break;
    }
  }
}


Quote
void intLights (int low, int high, int LEDlower1, int LEDraise1, int LEDlower2, int LEDraise2){ //takes the value from the pot and turns it into led values
    
  if(colorValue == 0) {
    digitalWrite(rr, LOW);
    digitalWrite(fr, LOW);
    
    digitalWrite(rg, LOW);
    digitalWrite(fg, LOW);
    
    digitalWrite(rb, LOW);
    digitalWrite(fb, LOW);
  }
  
  else if(colorValue >1000){
    digitalWrite(rr, HIGH);
    digitalWrite(fr, HIGH);
    
    digitalWrite(rg, HIGH);
    digitalWrite(fg, HIGH);
    
    digitalWrite(rb, HIGH);
    digitalWrite(fb, HIGH);
  }

else if (colorValue > low && colorValue < high){
  
  int LED1 = map (colorValue, low, high, 255, 10);
  int LED2 = map (colorValue, low, high, 10, 255);
  int LED3 = map (colorValue, low, high, 255, 10);
  int LED4 = map (colorValue, low, high, 10, 255);
  
  analogWrite (LEDlower1, LED1);
  analogWrite (LEDraise1, LED2);
  analogWrite (LEDlower2, LED3);
  analogWrite (LEDraise2, LED4);
  
}

 


Quote
 void ledFade (int f1, int f2, int f3, int r1, int r2, int r3, int delayTime, float fadeIncrementOn, float fadeIncrementOff){  
   
 for (float fadeValue = 0; fadeValue <=255 ; fadeValue +=fadeIncrementOn) { //fade door led's to on
   analogWrite (f1, fadeValue);
   analogWrite (f2, fadeValue);
   analogWrite (f3, fadeValue);
   analogWrite (r1, fadeValue);
   analogWrite (r2, fadeValue);
   analogWrite (r3, fadeValue);
   delay(delayTime);
   
   if ( digitalRead (alarmIn) == HIGH ){ //check to see if alarm is still armed
    digitalWrite (fg, LOW); // Turn all LED's off
    digitalWrite (fb, LOW);
    digitalWrite (fr, LOW);
    digitalWrite (rg, LOW);
    digitalWrite (rb, LOW);
    digitalWrite (rr, LOW);
    repeatCount=1;
    loop ();
    }
  } 
 
  for (float fadeValue = 255; fadeValue >=0 ; fadeValue -=fadeIncrementOff) { //fade door led's to off
   analogWrite (f1, fadeValue);
   analogWrite (f2, fadeValue);
   analogWrite (f3, fadeValue);
   analogWrite (r1, fadeValue);
   analogWrite (r2, fadeValue);
   analogWrite (r3, fadeValue);
   delay(delayTime);
    
    if ( digitalRead (alarmIn) == HIGH ){ //check to see if alarm is still armed
    digitalWrite (fg, LOW); // Turn all LED's off
    digitalWrite (fb, LOW);
    digitalWrite (fr, LOW);
    digitalWrite (rg, LOW);
    digitalWrite (rb, LOW);
    digitalWrite (rr, LOW);
    repeatCount=1;
    loop ();
    }
  }

digitalWrite (fg, LOW); // Turn all LED's off
digitalWrite (fb, LOW);
digitalWrite (fr, LOW);
digitalWrite (rg, LOW);
digitalWrite (rb, LOW);
digitalWrite (rr, LOW);

 if ( digitalRead (alarmIn) == HIGH ){ //check to see if alarm is still armed
    repeatCount=1;
    loop ();
    }
    
  delay(1000);
  
   if ( digitalRead (alarmIn) == HIGH ){//check to see if alarm is still armed
    repeatCount=1;
    loop ();
    }
      
 }

176  Forum 2005-2010 (read only) / Interfacing / question and suggestion on: July 31, 2010, 12:37:15 pm
I learn best by functional projects. i have been wanting to learn programming and improve my knowledge of component level electronics for quite a while. So i decided to integrate some led's into the door handles of my truck, they look cool and all, but i mostly wanted to do it because i would learn a lot in the process.

I have quite a few LED's i will be controlling so i am using some 3904 transistors to get the job done and keep the heavy lifting off the board.

So:

If i hook up an o-scope on the board side of the PWM output i see a great square wave. At the led it's not so pretty. Any idea why the pwn signal looks funky on the other side of the transistor? For the most part it works ok, i am just wondering if there is a better way to do this that i may be unaware of.

so here's some info and some code.

the resistor between the board and transistor is a 10K



177  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Multiple sets of "if" statements? on: October 18, 2009, 09:52:06 pm
I havn't been coding for very long (like 4 days ) but that loks really confusing to me, maybe it's because i don't see the rest or how the other variables are being derived i can't see the flow. any whoooo


IMHO it looks like you only want to turn on 'led' if all of the first statements are true.. in which case jezuz has it pegged, work it just like you set up the || in the bottom statement for 'ledtwo' but use && instead.

Just curious...

how can 'redvalue + 30' be >= to 'redVal' just befor you are testing to see if 'redvalue - 30' is <= to 'redVal' with nothing in between to change either of those values? same goes for the other values for each color and both LED's.... like i said maybe it's because i can't see the rest of the code but i can't seem to understand your flow.
178  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Freeware software to design circuits? on: October 14, 2009, 08:52:38 pm
I been using LTSpice. Works great for me, but i normally don't do very big circuits.
Pages: 1 ... 10 11 [12]