Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Push Button with two functions on: November 06, 2012, 07:49:57 pm
Hi PaulS and Arrch,

Thanks a lot for your help so far !

i do think i have something (by luck) which is working:

Code:
int currState;
int prevState = HIGH; // Assumes LOW means pressed
const int buttonPin = 2; // Connect the switch to this pin and to ground; no other wires or resistors needed
const int ledPin =  13; // My LED

// Variables will change:
long previousMillis = 0;        // will store last time LED was updated
int pressCount = 0;


// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 10000;           // interval for on time (milliseconds)



void setup()
{
   pinMode(buttonPin, INPUT);
   digitalWrite(buttonPin, HIGH);
   pinMode(ledPin, OUTPUT); 
}

void loop()
{
 
 
   currState = digitalRead(buttonPin);
   if(currState != prevState)
   {
      // The switch was just pressed or just released
      if(currState == LOW)
      {
         // Aha, it was just pressed
         pressCount++;
         if(pressCount > 2)
           pressCount = 1;
      }
   }
   prevState = currState;
   

if (pressCount == 1)  // here to switch on the LED
    digitalWrite(ledPin,HIGH);

 // here should be the timmer with millis(), ?
// after 5min i guess pressCount = 2

  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    pressCount = 2;  //turn off
  }


if (pressCount == 2) // here the switch off within the 5min
    digitalWrite(ledPin,LOW); 


   // Now, do something based on pressCount
   // 1 means pressed once - turn on LED
   // 2 means pressed twice - turn off LED

   // When you turn the LED on, note the time
   // If LED is on and has been on for the required time,
   // set pressCount to 2, so that next time around, the
   // LED will get turned off
}
2  Using Arduino / Programming Questions / Re: Push Button with two functions on: November 06, 2012, 06:15:21 pm
Thank You!

I am still at the beginning to learn the basics. I am afraid this all makes sense to me in few years. I assumed there must be a simple way to do this. However, i will just simple use the button to switch on the led for a specific time without the switch off function.

BTW: The real application is to switch on a kinetic artwork by pressing a button. To save live time of the work, it needs to be switch off automatically after 5min. It would be a nice add to be a able to switch it off before the 5min ends. This, with the same Button.

I do hope at one time arduino get's just a good tool which is working for me  smiley-confuse

pe
3  Using Arduino / Programming Questions / Re: Push Button with two functions on: November 06, 2012, 04:43:18 pm
hi Arrch,

you right, but my question is where to start. The basic code is form the button example. My problem is how the same button can turn of the LED within the delay time. Sure the code "stuck" by the delay.... this will not work

i try again to explain:
I have a LED which i can turn on with a Pushbutton. The LED will be on for, lets say 10min and will then turn off automatically. Here my problem: I would like to be able to switch off with the same Pushbutton the LED within the 10min.


Code:

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:   
    digitalWrite(ledPin, HIGH); 
    delay(100000);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}
4  Using Arduino / Programming Questions / Push Button with two functions on: November 06, 2012, 04:07:51 pm
hi,

I do dry this for some time but no luck:

Pushbutton press = LED on for 10min, then off

Pushbutton press within the 10min = LED off


Basically the same button can turn off the led within the 10min.

I can't find a solution so far. It should be simple to use it later on a ATtiny45.

Thanks a lot for any help.

Pe
5  Using Arduino / Motors, Mechanics, and Power / Re: Absolute Position for Stepper Motors and linear axis on: December 27, 2011, 06:46:05 pm
thanks for all that help.

agree, i running a cnc machine in openloop, no encoder needed. The pitch of spindels function further as a gear reduction.

thanks also to johnwasser, this helps a lot. Now i have to try to integrate this in my simple coding practice..

i will post my code + images from the project as soon it works (or ask for more help smiley

great !

best, pe
6  Using Arduino / Motors, Mechanics, and Power / Re: Absolute Position for Stepper Motors and linear axis on: December 24, 2011, 08:19:59 am
thanks cr0sh and johnwasser,

@cr0sh: i would rather not use any encoders, the project would be then to expensive

@johnwasser:

- yes, there will be a end-switch which give me the initial position.

- loosing power will start a new initialization process and i make sure to not lose any steps from the motors.

- keeping track of the absolute postition is my problem. It would be very easy doing this in "Max/msp" but as a beginner in arduino i am mostliy struggeling with the left / right and counting in both ways postitive values. How difficult is this for a beginner ?

thanks pe

btw, my setup is:

LM Guide Actuator thk KR33
nema 23 steppers
arduino uno
pololu A4988 drivers
7  Using Arduino / Motors, Mechanics, and Power / Absolute Position for Stepper Motors and linear axis on: December 23, 2011, 09:31:57 pm
Hi,

I using a "direction / Step" Driver for a Steppermotor with an linear axis and i would like to define the axis with absolute positions numbers in order to simple call this numbers and move the "runner block" to this position.

lets say:

left end of the linearaxis:        0
right end of the linearaxis: 1000
middle of the linearaxis:      500
etc


how to translate the "steps numbers" and "direction low/high" to

-go to absolute position: 300
-go to absolute position: 100
-go to absolute position: 150
-go to absolute position: 900
-go to absolute position: 990
-etc
?

any advice or someone can point me in the right direction ?

thanks, pe
8  Community / Exhibition / Gallery / Re: 441 water drops on: April 28, 2011, 09:34:34 pm
Very cool - I love those little spheres. What instigated the project?

it was for a group exhibition here in berlin with the titel: decay.

i actualy built a cnc router, during that i found it more fun to test the program routines with water drops

thanks all, also for the help (for my projects) i got here !


9  Community / Exhibition / Gallery / Re: 441 water drops on: April 26, 2011, 07:50:00 am
thanks,

well there is not much to say. Arduino control's the stepperdriver, step's and direction. Linearaxis are THK (secandhand). Little relay to trigger the dispenser.

the code is kind of mess... was last minut project..

Code:
/*

Falling objects - positioning systems
is an machine that adds drops of water onto a special textured surface.
Each drop forms into an almost perfect sphere through the surface tension
of the water and the omniphopic Material.
The electronically controlled pipette wanders through a square grid of 21 x 21 drops
to form a micro-matrix and returns to the beginning.
After approximately 300 minutes, and when the water drops have evaporated, the same process starts again.

http://pelang.ch/

*/



int dirpin1 = 11; //Stepper 1, Direction
int steppin1 = 12; //Stepper 1, Steps
int dirpin2 = 9; //Stepper 2, Direction
int steppin2 = 10; //Stepper 2, Steps
int enableX = 5; // Enable driver X
int enableY = 4; // Enable driver Y
int relay = 8; //Relay
int Xdrops = 20; //numbers of x drops
int Pause = 100; // Pause wenn Drops
int PauseDrop = 50; //whait befor drop
int limitX = 7; // limitswitch X achse
int limitY = 6; // limitswitch X achse
int switchstateX = 0;
int switchstateY = 0;
int Xsize = 300;  //distance from each drop
int Ysize = 3000; //distance from each drop


void setup() {
 
  pinMode(steppin1, OUTPUT);   
  pinMode(dirpin1, OUTPUT);
  pinMode(steppin2, OUTPUT);   
  pinMode(dirpin2, OUTPUT);
  pinMode(enableX, OUTPUT);
  pinMode(enableY, OUTPUT);
  pinMode(relay, OUTPUT);
  pinMode(limitX, INPUT);
  pinMode(limitY, INPUT);

digitalWrite(enableX, HIGH); //Schaltet X Diver ON
digitalWrite(enableY, HIGH); //Schaltet X Diver ON

/* this is for limitng the xy at the very beginning */

// limiting X

  int b;
 
  digitalWrite(dirpin1, LOW); // Set X the direction.
  for (b = 0; b<10000; b++)                                                       
      {
        switchstateX = digitalRead(limitX);
        if (switchstateX == HIGH)
        {
        digitalWrite(steppin1, HIGH); 
        digitalWrite(steppin1, LOW);   
        delayMicroseconds(800);       
        }
        else
        {
        }
       } 
   digitalWrite(dirpin1, HIGH); // Set X the direction.   
   for (b = 0; b<7800; b++)                                                       
        {
        digitalWrite(steppin1, HIGH); 
        digitalWrite(steppin1, LOW);   
        delayMicroseconds(800);       
        } 
       
       
 // limiting Y

  long g;
 
  digitalWrite(dirpin2, HIGH); // Set X the direction.
  for (g = 0; g<100000; g++)                                                       
      {
        switchstateY = digitalRead(limitY);
        if (switchstateY == HIGH)
        {
        digitalWrite(steppin2, HIGH); 
        digitalWrite(steppin2, LOW);   
        delayMicroseconds(300);       
        }
        else
        {
        }
       } 
   digitalWrite(dirpin2, LOW); // Set X the direction.   
   for (g = 0; g<68000; g++)                                                       
        {
        digitalWrite(steppin2, HIGH); 
        digitalWrite(steppin2, LOW);   
        delayMicroseconds(300);       
        }         
       
}




void loop()
{
 int i;
 int k;
 int b;
 int m;
 long r;
 
digitalWrite(enableX, HIGH); //Schaltet X Diver ON
digitalWrite(enableY, HIGH); //Schaltet X Diver ON


 for (m = 0; m<10; m++) // Make 5 Lines of 5 Drops
  {
   digitalWrite(dirpin1, LOW); // Set X the direction.
   digitalWrite(dirpin2, HIGH); // Set Y the direction.
 
    {
 // move Y 1 line
     for (b = 0; b<Ysize; b++)                                                       
       {
        digitalWrite(steppin2, HIGH); 
        digitalWrite(steppin2, LOW);   
        delayMicroseconds(1200);             
       }     
// make drops
      delay(PauseDrop); //whait befor drop
      digitalWrite(relay, HIGH);   // turn Relay on
      delay(Pause);              // wait for a second
      digitalWrite(relay, LOW);    // turn Relay off
      delay(Pause);              // wait for a second
     
     
 // move X 10 times forward       
     for (i = 0; i<Xdrops; i++) // Make N Drops forward X

     { 
       for (k = 0; k<Xsize; k++)  // Make 80 Steps = 1mm
                                                        //  Moving X Axis 10 Steps CW
         {
          digitalWrite(steppin1, HIGH);                 
          digitalWrite(steppin1, LOW);   
          delayMicroseconds(1200);           
         }

 // make drops
         delay(PauseDrop); //whait befor drop
         digitalWrite(relay, HIGH);   // turn Relay on
         delay(Pause);              // wait for a second
         digitalWrite(relay, LOW);    // turn Relay off
         delay(Pause);              // wait for a second
       }
      }
     
// move Y 1 line   
     for (b = 0; b<Ysize; b++)                                                       
       {
        digitalWrite(steppin2, HIGH); 
        digitalWrite(steppin2, LOW); 
        delayMicroseconds(1200);           
        }

// make drop
       delay(PauseDrop); //whait befor drop
       digitalWrite(relay, HIGH);   // turn Relay on
       delay(Pause);              // wait for a second
       digitalWrite(relay, LOW);    // turn Relay off
       delay(Pause);              // wait for a second
   
       
// change direction of X   
      digitalWrite(dirpin1, HIGH); // Set the direction.


// move X 10 times backwards     
     {
       for (i = 0; i<Xdrops; i++)

        {
         for (k = 0; k<Xsize; k++) // Make 80 Steps = 1mm
 
           {
            digitalWrite(steppin1, HIGH); 
            digitalWrite(steppin1, LOW);   
            delayMicroseconds(1200);           
           }
// make drops
          delay(PauseDrop); //whait befor drop
          digitalWrite(relay, HIGH);   // turn Relay on
          delay(Pause);              // wait for a second
          digitalWrite(relay, LOW);    // turn Relay off
          delay(Pause);              // wait for a second
         }
      }     
   
  }
 
}




// last line last line last line last line last line

// move Y 1 line   
     for (b = 0; b<Ysize; b++)                                                       
       {
        digitalWrite(steppin2, HIGH); 
        digitalWrite(steppin2, LOW); 
        delayMicroseconds(1200);           
        }

// make drop
       delay(PauseDrop); //whait befor drop
       digitalWrite(relay, HIGH);   // turn Relay on
       delay(Pause);              // wait for a second
       digitalWrite(relay, LOW);    // turn Relay off
       delay(Pause);              // wait for a second
   
       
// change direction of X   
      digitalWrite(dirpin1, LOW); // Set the direction.


// move X 10 times backwards     
     {
       for (i = 0; i<Xdrops; i++)

        {
         for (k = 0; k<Xsize; k++) // Make 80 Steps = 1mm
 
           {
            digitalWrite(steppin1, HIGH); 
            digitalWrite(steppin1, LOW);   
            delayMicroseconds(1200);           
           }
// make drops
          delay(PauseDrop); //whait befor drop
          digitalWrite(relay, HIGH);   // turn Relay on
          delay(Pause);              // wait for a second
          digitalWrite(relay, LOW);    // turn Relay off
          delay(Pause);              // wait for a second
         }
      } 



     
     
// Home xy
  digitalWrite(dirpin1, HIGH); // Set X the direction.
  digitalWrite(dirpin2, LOW); // Set Y the direction. 
 

  {
   for (r = 0; r<(Xsize * Xdrops); r++) // X go back to beginng
 
   {
    digitalWrite(steppin1, HIGH);   // For test with LED on
    digitalWrite(steppin1, LOW);    // For test with LED off
    delayMicroseconds(1200);              // wait for a second
    }
   
    for (r = 0; r<66000; r++) // Y go back to beginng
 
   {
    digitalWrite(steppin2, HIGH);   // For test with LED on
    digitalWrite(steppin2, LOW);    // For test with LED off
    delayMicroseconds(400);              // wait for a second
    }

  }

digitalWrite(enableX, LOW); //Schaltet X Diver OFF
digitalWrite(enableY, LOW); //Schaltet X Diver OFF

delay(5000); // verdunsten
 
}




10  Using Arduino / Project Guidance / Re: 6 Motors doing different tasks at the same time on: April 23, 2011, 06:21:37 am
Your Event Manager is the perfect solution for me, works very well. In case, here is my code for two motors:

Code:
/*
 
 this program runs two motors at different speeds and lenght.
 Pins are connected to a L293D, Probably PWM needs to adjust
 to run your motors.
 
 Thanks to TeslaFan for his Event Manager:
 http://roboticcore.com/?p=14
 
 */
 
#include "EventManager.h"

void Motor1AHandler(void)
  {
   char random_pwm;
   long random_time;
   random_pwm = random(17, 49);
   random_time = random(5000, 33000);
   digitalWrite(0, HIGH);    // Set the direction.
   digitalWrite(1, LOW);   
   analogWrite(3, random_pwm);   // Set the speed.
  AddEvent(TIMER,ONE_SHOT,random_time,Motor1BHandler);
  }
void Motor1BHandler(void)
  {
   char random_pwm;
   long random_time;
   random_pwm = random(17, 49);
   random_time = random(5000, 33000);   
   digitalWrite(0, LOW);    // Set the direction.
   digitalWrite(1, HIGH);   
   analogWrite(3, random_pwm);   // Set the speed.
  AddEvent(TIMER,ONE_SHOT,random_time,Motor1AHandler);
  }


void Motor2AHandler(void)
  {
   char random_pwm;
   long random_time;
   random_pwm = random(17, 49);
   random_time = random(5000, 33000);
   digitalWrite(12, HIGH);    // Set the direction.
   digitalWrite(13, LOW);   
   analogWrite(11, random_pwm);   // Set the speed.
  AddEvent(TIMER,ONE_SHOT,random_time,Motor2BHandler);
  }
void Motor2BHandler(void)
  {
   char random_pwm;
   long random_time;
   random_pwm = random(17, 49);
   random_time = random(5000, 33000);   
   digitalWrite(12, LOW);    // Set the direction.
   digitalWrite(13, HIGH);   
   analogWrite(11, random_pwm);   // Set the speed.
  AddEvent(TIMER,ONE_SHOT,random_time,Motor2AHandler);
  }
 


void setup()
  { 
  int pwmfreq = 1; // set the PWM freq
  TCCR2B = (TCCR2B & 0xF8) | pwmfreq;
 
  pinMode(13, OUTPUT); // MotorBlock1
  pinMode(12, OUTPUT); //
  pinMode(11, OUTPUT); // PWM
 
  pinMode(0, OUTPUT); // MotorBlok2
  pinMode(1, OUTPUT); //
  pinMode(3, OUTPUT); // PWM
 
  digitalWrite(13, LOW);   
  digitalWrite(12, LOW);     
  digitalWrite(11, LOW);   
  digitalWrite(3, LOW);
  digitalWrite(1, LOW);
  digitalWrite(0, LOW);
 
  // Initialize the Event Handler System.
  InitEvents();
 
  // Start Motor 1 event chain. Other motor starts are below.
  AddEvent(TIMER,ONE_SHOT,1000,Motor1AHandler);
  AddEvent(TIMER,ONE_SHOT,1000,Motor2AHandler);
  }


void loop()
  {
  ProcessEvents(millis());
  }
11  Using Arduino / Project Guidance / Re: 6 Motors doing different tasks at the same time on: April 22, 2011, 07:22:02 am
Thanks CrossRoads and TeslaFan,

@TeslaFan: This was exactly what i am looking for. Thank you.

You right with the "linear thinking" but i still have to get it right...(means drinking a big cap of coffee and reading your blog about Envent Manager)

here is a examle of two LED's blinking (cool) randomly:
Code:
#include "EventManager.h"

void Motor1AHandler(void)
  {
   long random_time;
   random_time = random(900);   
   digitalWrite(13, HIGH);    // Set the LED13 on.
  AddEvent(TIMER,ONE_SHOT,random_time,Motor1BHandler);
  }
void Motor1BHandler(void)
  {
   long random_time;
   random_time = random(900);   
   digitalWrite(13, LOW);    // Set the LED13 off.
  AddEvent(TIMER,ONE_SHOT,random_time,Motor1AHandler);
  }


void Motor2AHandler(void)
  {
   long random_time;
   random_time = random(900);   
   digitalWrite(12, HIGH);    // Set the LED12 on.
  AddEvent(TIMER,ONE_SHOT,random_time,Motor2BHandler);
  }
void Motor2BHandler(void)
  {
   long random_time;
   random_time = random(900);   
   digitalWrite(12, LOW);    // Set the LED12 off.
  AddEvent(TIMER,ONE_SHOT,random_time,Motor2AHandler);
  }


void setup()
  {
  pinMode(13, OUTPUT); // LED13.
  pinMode(12, OUTPUT); // LED12.
 
  digitalWrite(13, LOW);    // set the LED13 off.
  digitalWrite(12, LOW);    // set the LED12 off. 
  // Initialize the Event Handler System.
  InitEvents();
 
  // Start Motor 1 event chain. Other motor starts are below.
  AddEvent(TIMER,ONE_SHOT,1000,Motor1AHandler);
  AddEvent(TIMER,ONE_SHOT,1000,Motor2AHandler);
  }


void loop()
  {
  ProcessEvents(millis());
  }
12  Community / Exhibition / Gallery / 441 water drops on: April 21, 2011, 08:45:12 pm

Machine that adds drops of water onto a special textured surface. Each drop forms into an almost perfect sphere through the surface tension of the water and the omniphopic Material. The electronically controlled pipette wanders through a square grid of 21 x 21 drops to form a micro-matrix and returns to the beginning. After approximately 300 minutes, and when thewater drops have evaporated, the same process starts again.

http://pelang.ch/video/falling_objects_positioning_systems.mov

13  Using Arduino / Project Guidance / 6 Motors doing different tasks at the same time on: April 21, 2011, 08:27:16 pm
hi,

i can't get my head around this problem:

1x Arduino uno, 3 x L293D, 6 x Gearmotor

Motor1: run for (random) time, (random) speed, then stop and change direction, again run for (random) time, (random) speed
at the same time:
Motor2: run for (random) time, (random) speed, then stop and change direction, again run for (random) time, (random) speed
at the same time:
Motor3: run for (random) time, (random) speed, then stop and change direction, again run for (random) time, (random) speed
and so one...

my problem here is that all six motors doing this (differently) at the same time. one after the other would be easy to do...

Do i miss something essential ? any ideas where to go ?

thanks, Pe
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: simple matrix on: September 12, 2009, 03:46:02 am
thanks zed0, it works perfect now.

slowly i start to understand how the code is working...


15  Forum 2005-2010 (read only) / Syntax & Programs / Re: simple matrix on: September 11, 2009, 04:05:53 pm
hi

question: i want to have a delay of 13min between the changes. the problem is that the code runs a fist time complet (means with the 13 min delay) before the leds are the first time blinking.

where i have to place the (LIGHTOFF_DELAY) to run the leds at the beginning when i turn on the arduino ?

//http://arduino.cc/en/Reference/Const
const long LIGHT_DELAY = 110000;
const long LIGHTOFF_DELAY = 780000;
const byte MATRIX_WIDTH = 6;
const byte MATRIX_HEIGHT = 6;

//hold the pin numbers of the matrix
const byte matrix[MATRIX_HEIGHT][MATRIX_WIDTH] = {
      { 2, 3, 4  }, //matrix[0][0] , matrix[0][1] , matrix[0][2]
      { 5, 6, 7  }, //matrix[1][0] , matrix[1][1] , matrix[1][2]
      { 8, 9, 10 }, //matrix[2][0] , matrix[2][1] , matrix[2][2]
        { 2, 5, 8  }, //matrix[0][0] , matrix[0][1] , matrix[0][2]
      { 3, 6, 9  }, //matrix[1][0] , matrix[1][1] , matrix[1][2]
      { 4, 7, 10 }, //matrix[2][0] , matrix[2][1] , matrix[2][2]
};

void setup(){
      //set pins as OUTPUT
      for (byte y=0; y<MATRIX_HEIGHT; y++){
            for (byte x=0; x<MATRIX_WIDTH; x++){
                  pinMode( matrix[y]
  • , OUTPUT );
           }
      }

      //http://arduino.cc/en/Reference/RandomSeed
      randomSeed(analogRead(0));
}

void loop(){
      //http://arduino.cc/en/Reference/Random
      boolean doLightColumn = random(1);
      if (doLightColumn){
            //select a random index
            byte idx = random(MATRIX_WIDTH);
            //light the column at that index
            lightColumn( idx );
      } else {
            //select a random index
            byte idx = random(MATRIX_HEIGHT);
            //light the row at that index
            lightRow( idx );

      }
      //make actions visible
      delay(LIGHT_DELAY);
}

void lightColumn( byte idx ){
      matrixOff();
      for (byte y=0; y<MATRIX_HEIGHT; y++){
            digitalWrite( matrix[y][idx] , HIGH );
      }
}

void lightRow( byte idx ){
      matrixOff();
      for (byte x=0; x<MATRIX_HEIGHT; x++){
            digitalWrite( matrix[idx]
  • , HIGH );

      }

}


void matrixOff(){
      for (byte y=0; y<MATRIX_HEIGHT; y++){
            for (byte x=0; x<MATRIX_WIDTH; x++){
                  digitalWrite( matrix[y]
  • , LOW );

            }

      }

 delay(LIGHTOFF_DELAY);
 
}



Pages: [1] 2