Show Posts
Pages: [1] 2 3 ... 10
1  Using Arduino / Programming Questions / Re: getting rid of delay(), fading LEDs on: March 07, 2014, 02:54:36 pm
hi robin
oh sorry i thought maybe it'b be better to start over. how do i ask the moderator to merge?

i'm getting real close to giving up and just using 2 arduinos and delay(). this is making me feel so dumb!

are there any libraries or anything that can make this easier that anyone knows about? it'd be so nice to have a library that made a delay() not stop code and that made an led fade on, stay on or fade off with just one function. ugh. my brain is just not able to wrap around this stuff!
would the timer library be worth using here? i don't understand why everything in the examples with that happens in setup(), though.

thanks again for all the help!
2  Using Arduino / Programming Questions / Re: getting rid of delay(), fading LEDs on: March 07, 2014, 12:47:18 pm
hello,

i was posting a similar question elsewhere but i wanted to start a new topic with a more precise question.

i want to fade an LED on, keep it on, fade it off, keep it off, and then go to the next one and do the same thing, 4 times...all without using delay() anywhere.

I am close. I can fade it on,  and keep it off. for some reason i am not able to wrap my head around how to fade it off or keep it on.  Just wondering if anyone has any guidance. here is the function:

Code:
void one() {
  unsigned long currentTime=millis();

  if (ONEswitch==true) {

    if (currentTime>=loopTime+20){
      brightness1 = brightness1 + fadeAmount;
      analogWrite(led1, brightness1);
      loopTime=currentTime;


      if (brightness1 >= 255) {  //once it peaks
        if (currentTime - previousMillis > interval){    //delay(3000); (i wish this worked :-(//
          previousMillis=currentTime;
        }

        for (int i=255;i>0;i=i-2){  //fade it back down
          analogWrite(led1, i);
          delay(20); //how can i get rid of this?        
        }

        //switch to change to 2nd LED
        ONEswitch=false;
        TWOswitch=true;
        THREEswitch=false;
        FOURswitch=false;
      }
    }
  }
  else {
    brightness1=0;
    digitalWrite(led1, LOW);
  }

}
3  Using Arduino / Programming Questions / Re: getting rid of delay(), fading LEDs on: March 06, 2014, 02:40:52 pm
Hi Robin,

Thanks so much for the help. I'm trying to pair down your sketch to get it to work with fading LEDs.

I've got the loop going and stuff coming on and off using analogWrite. I'm having trouble implementing the fades....right now led_A_State is set so i thought it would fade...it's just very dim. led_B_State is just set to on and off (0 or 255) and is working fine. Anyway, here's what I have so far. Any help understanding what's going on is much appreciated! Thanks.

edit - also, weirdly, after a few minutes, the A and B LEDs just stop turning on and off. What is going on?!

thanks!

Code:

// --------CONSTANTS (won't change)

const int LoopLedPin =  11;      // the pin numbers for the LEDs
const int led_A_Pin = 10;
const int led_B_Pin = 9;


//const int onBoardLedInterval = 500; // number of millisecs between blinks

//#of secs between blinks
const int led_A_Interval = 8500;
const int led_B_Interval = 19000;

const int blinkDuration = 5000; // number of millisecs that Led's are on



//------------ VARIABLES (will change)

//byte onBoardLedState = LOW;             // used to record whether the LEDs are on or off
//byte led_A_State = LOW;           //   LOW = off
//byte led_B_State = LOW;

int led_A_State = 0;
int led_B_State=0;

unsigned long currentMillis = 0;    // stores the value of millis() in each iteration of loop()
unsigned long previousOnBoardLedMillis = 0;   // will store last time the LED was updated
unsigned long previousLed_A_Millis = 0;
unsigned long previousLed_B_Millis = 0;

int brightness1=0;
int fadeAmount1=2;
int loopTime;

int periode = 3000;
int displace = 500;
int value2, time;
//==============

void setup() {

  // set the Led pins as output:
  pinMode(LoopLedPin, OUTPUT);
  pinMode(led_A_Pin, OUTPUT);
  pinMode(led_B_Pin, OUTPUT);

}

//===========

void loop() {

  // Notice that none of the action happens in loop() apart from reading millis()
  //   it just calls the functions that have the action code

  currentMillis = millis();   // capture the latest value of millis()
  //   this is equivalent to noting the time from a clock
  //   use the same time for all LED flashes to keep them synchronized

  loopingLedState();
  updateLed_A_State();
  updateLed_B_State();
  switchLeds();
}

//============

void loopingLedState() {
   time = millis();
   value2 = 128+127*cos(2*PI/periode*(displace-time));
}

//===========

void updateLed_A_State() {

  if (led_A_State == 0) {
    if (currentMillis - previousLed_A_Millis >= led_A_Interval) { //fade on and keep on
     // led_A_State = 255;
     led_A_State = led_A_State+2;
     previousLed_A_Millis=currentMillis;
    
     if (led_A_State >= 255){
       led_A_State = 255;
     }
      previousLed_A_Millis = currentMillis;
    }
  }
  else {
    if (currentMillis - previousLed_A_Millis >= blinkDuration) { //fade off
      led_A_State = 0;
      previousLed_A_Millis = currentMillis;
    }
  }
}

//=========

void updateLed_B_State() {

  if (led_B_State == 0) {
    if (currentMillis - previousLed_B_Millis >= led_B_Interval) { // fade on and keep on
      led_B_State = 255;
      previousLed_B_Millis = currentMillis;
    }
  }
  else {
    if (currentMillis - previousLed_B_Millis >= blinkDuration) { //fade off
      led_B_State = 0;
      previousLed_B_Millis = currentMillis;
    }
  }
}

//============

void switchLeds() {
  // this is the code that actually switches the LEDs on and off

  analogWrite(LoopLedPin, value2);
  analogWrite(led_A_Pin, led_A_State);
  analogWrite(led_B_Pin, led_B_State);
}

//=============



//==========END


4  Using Arduino / Programming Questions / Re: getting rid of delay(), fading LEDs on: March 06, 2014, 12:36:24 pm
thank you all for your help!

man...this is REALLY hard to wrap my head around. is it absolutely necessary to use an FSM? i'm having a hard time even getting an LED to blink using switch() and case.

what does this mean exactly? if (sequence0()==finished) ?

so i put the sequence0() function somewhere else and when that's done it breaks and goes to the next case... but what is the 'finished' variable? that wasn't defined anywhere. is it a boolean or something? that i switch from false to true in the functions?

also since this is a case by case code...i put the constantly pulsing pins in the void loop, followed by the FSM for the fade in, on, fade out, off ? then after i put the functions that actually do the things i want?

thanks for any more explanation. this seems so simple but it's so hard for me to understand!!
5  Using Arduino / Programming Questions / getting rid of delay(), fading LEDs on: March 05, 2014, 05:45:17 pm
I'm having trouble figuring out how to multitask LEDs. I'm not even sure if this is possible...can I get so many smooth fades?

these are the functions i want to do...sequence3() would be pulsing constantly while the other ones are fading on, staying on, fading off:

sequence1() {
//fade to on after sequence2() fades off
//leave on, at 255 brightness for 10 seconds
//fade off
}
sequence2() {
//fade to on after sequence1() finishes
//leave on, at 255 brightness for 10 seconds
//fade off
}

sequence3() {
//fade up
//fade down
//loop this so this is happening all the time
}

void loop() {
sequence1();
sequence2();
sequence3();
}

this is what i have so far...it works starting out but then the pulsing lights stop turning on

Code:
boolean switchOn1, switchOn2;
unsigned long currentTime;
unsigned long loopTime;
unsigned long currentTime1;
unsigned long loopTime1;
int brightness = 0;    // how bright the LED is
int fadeAmount = 1;    // how many points to fade the LED by

int brightness1 = 0;    // how bright the LED is
int fadeAmount1 = 2;    // how many points to fade the LED by

void setup() {
  switchOn1=true;
  switchOn2=false;

  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
}


void sequence1() {
  //fade to on after sequence2() fades off
  //leave on, at 255 brightness for 10 seconds
  //fade off

  //if the switch is true
  //fade on the led
  //leave on the led for 2 seconds
  //flip the switch to false
  //flip on the switch that turns on the next set
  //fade it out

  if (switchOn1 == true){
    currentTime=millis();
    if(currentTime >=loopTime+20){
      analogWrite(10, brightness);
      brightness = brightness + fadeAmount;

      loopTime = currentTime;
      if (brightness >=255){
        analogWrite(10, 255);
        if (currentTime >=loopTime+2000){
          analogWrite(10, 255);
        }
        else {
          analogWrite(10,0);
          switchOn1=false;
          switchOn2=true;
        }
        loopTime=currentTime;
      }
      loopTime=currentTime;
    }
  }
}
void sequence2() {
  //fade to on after sequence1() finishes
  //leave on, at 255 brightness for 10 seconds
  //fade off
    if (switchOn2 == true){
    currentTime=millis();
    if(currentTime >=loopTime+20){
      analogWrite(9, brightness);
      brightness = brightness + fadeAmount;

      loopTime = currentTime;
      if (brightness >=255){
        analogWrite(9, 255);
        if (currentTime >=loopTime+2000){
          analogWrite(9, 255);
        }
        else {
          analogWrite(9,0);
          switchOn1=true;
          switchOn2=false;
        }
        loopTime=currentTime;
      }
      loopTime=currentTime;
    }
  }
}

void sequence3() {
  //fade up
  //fade down
  //loop this so this is happening all the time

  currentTime1=millis();
  if(currentTime1 >=loopTime1+20){
    analogWrite(11, brightness1);
    brightness1 = brightness1 + fadeAmount1;
    if (brightness1 ==0 || brightness1 == 255) {
      fadeAmount1 = -fadeAmount1;
    }
    loopTime1 = currentTime1;

  }

}

void loop() {
  sequence1();
  sequence2();
  sequence3();
}


6  Using Arduino / Project Guidance / led series and transistor on: February 21, 2014, 11:02:17 am
i'm decorating a 40' table with little dioramas that get lit up by randomly pulsing LEDs. I just bought a bunch of these but in different colors:
https://www.sparkfun.com/products/8860

forward voltage around 3.3 for most or 2.2 for red and yellow. 80mA is forward current.

i used this http://led.linear1.org/led.wiz webpage to calculate resistor size if i put them in series of 2 or 3 at a time. the resistors are mostly 1/2W or 1W. usually when i use them with these LEDs they run hot which is a little disconcerting.

i want to put around 6 leds (two or three series of them) into one tip120 which, going through a 1k resistor, goes into a PWM pin in arduino. There will be 24 leds in all and 4 tip120s.

then also i will use a second arduino to pulse 8 lights (4 series) going through 1 tip120, through 1k resistor, to an arduino pin.

can you put so many LEDs on one tip120? would a mosfet be better? will it be okay to do PWM using a transistor? do you think i need a heat sink for the transistor? any idea why the resistors become hot to the touch?

I want to power everything with a 12v, 5amp wall wort. here's a rough idea of what i mean (without actually having the craziness of 32 leds):

7  Using Arduino / Motors, Mechanics, and Power / Re: bipolar stepper losing torque on: October 03, 2013, 11:16:51 am
thanks so much for the feedback! when i remove the zoetrope from the shaft everything works fine. I am half stepping the motor, is that the same as microstepping? it's not whole stepping. i tried doing quarter steps and even 1/8 steps but that made it worse. i put it on whole stepping and the motor started up better but now the timing is off for the zoetrope effect. also...what do you mean by Mol? and i was also curious about amperage. would giving the circuit more amps help? right now it's getting 12amps which already seems like a lot...thanks again!
8  Using Arduino / Motors, Mechanics, and Power / bipolar stepper losing torque on: October 03, 2013, 10:12:06 am
hello,

I made a 3d printed zoetrope using an arduino to control the startup and RPM of a bipolar stepper (this one: https://www.sparkfun.com/products/9238)

I am using this code: https://github.com/xtremd/Zoetrope/tree/master/zoetrope

When I originally made it, I had a CNC'd piece of plexi around the shaft of the motor and everything was working fine. This is obviously temporary as the plexi began to strip a bit so I had a piece of aluminum made for the motor shaft with a set screw (the plexi just fit around perfect on the shaft)
Now, for a reason I do not understand, the motor is unable to spin the 3d print around.

Why would a stepper work okay with a crummy plexi shaft coupling and fail with a nice aluminum coupling? Both couplings weigh around the same but the 3d print weighs quite a bit so a small weight difference doesn't seem like it would matter.

I am pretty new to steppers and they are always really confounding me.

Powering it through an ATX psu...5amps. Would more amps help you think? Does that matter?

Any ideas much appreciated!!
9  Using Arduino / General Electronics / using ATX12V PSU for arduino/stepper/LED array on: June 13, 2013, 04:56:24 pm
Hello,

I've made some posts about this before, I'm making a 3D zoetrope/strobescope sculpture using an arduino and a stepper. I'm getting very close now! The problem is, is that there is a little bit of drift on my objects being animated. I have the program strobing 15 times per rotation because there are 15 objects to animate. The problem is that the objects don't stay still, but drift a little to the left. I feel like maybe it's because I'm not powering the project correctly and the stepper slows down just a little and speeds back up each rotation.
So
I want to swap out the 12V 5A wall wort that I'm using and use an ATX PSU I have laying around.
It's 12V 8A, or 14A. I was going to use a few different outputs to power the arduino, the motor and the LED array separately. So my question is, is that can I damage anything giving so much amperage? I remember reading somewhere that steppers have a maximum current rating or something. Is there any way to find out what mine is? I can't find the datasheet anywhere for it but I know it's a 1.8degree stepper at 200 pulses per rotation. A pretty standard little stepper that someone who worked at MakerBot gave me awhile ago. I think they used them in the old replicators. Could I damage the Arduino if I use one of the 5V outputs? It says the 5V ones are 20A.
Thanks so much for any input!
10  Using Arduino / General Electronics / Re: difference between a tip120 and mosfet on: June 07, 2013, 09:25:54 am
Oh gosh perfect! Thanks so much! That really helps! The tip120 was getting hot! I'll get a MOSFET
11  Using Arduino / General Electronics / difference between a tip120 and mosfet on: June 07, 2013, 08:57:51 am
hello,

i just want to strobe an array of around 360 little LEDs all hooked together. They turn on and strobe fine with a 12V, 5amp wall wort. I've been using a TIP120 to strobe them from my arduino. Is this okay? Should I be using a mosfet? What's the difference really?

thanks!
12  Using Arduino / General Electronics / Re: no response from stepper on: June 06, 2013, 09:28:41 pm
Thanks for the advice. I didn't do any of that stuff. I always have the arduino on first, upload the code and then apply the 12V. Everything was off when I was checking the resistance. The arduino out pins are working.

Has anyone else had this problem? I googled around and found a few other people with this problem but no responses. I know it's a long shot. Just wondering if there was anything obviously wrong from the picture or any little thing I'm missing.
13  Using Arduino / General Electronics / no response from stepper on: June 06, 2013, 04:30:20 pm
hello,
i just got a big easy driver stepper motor driver from SparkFun. I wanted my stepper to run a little smoother than it did with an h-bridge and plus i fried the h-bridge chip anyway running some weird code. i'm very new to steppers and having the hardest time with them for some reason.

so i hooked up the big easy driver just like in this tutorial: http://bildr.org/2012/11/big-easy-driver-arduino/#mototPairs

ran the code from the page (one_stepper_example.ino)

uploaded it to arduino, gave the easy driver 12V. the light on the driver turned on, the arduino took the code, but there is 0 reaction from both steppers i tried. i multimetered everything out and it's going where it should, i think. there is one thing, though, that when i multimeter from the stepper wire onto the easyDriver board, it is a little strange. A1 beeps for A1, but when I test A2 to A2 nothing beeps. A2 does beep, though, on A1. Same exact thing with the B wires. I assume this is because there is resistance in the motor and stuff like that i don't understand. does everything sound hooked up correctly? and if it is hooked up correctly, any idea why i'm getting no response from the motor? i'm using a 12V 5A wall wort. I messed around with the potentiometer on the driver also to no avail.

here's what the board looks like in case anyone could notice any glaring mistakes...
https://dl.dropboxusercontent.com/u/7072449/2013-06-06%2017.27.21.jpg

thanks so much for any feedback
14  Using Arduino / Project Guidance / Re: code with zoetrope with stepper on: June 05, 2013, 03:00:13 pm
oh wow i found this: https://github.com/xtremd/Zoetrope

for anyone curious. i'm waiting for my easyDriver to come in the mail then i'll try it out.
thanks so much for all the comments.
15  Using Arduino / Project Guidance / Re: code with zoetrope with stepper on: June 05, 2013, 11:22:41 am
thanks so much. but why would the above code have fried my h-bridge chip? now i have to wait to get new parts in the mail to test out the rest of the code.
here was how i had it wired up: http://arduino.cc/en/uploads/Tutorial/bipolar_schem.jpeg
i'll report back when the stuff comes in

thanks
Pages: [1] 2 3 ... 10