Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 28, 2013, 06:45:22 pm
Paul this could go on for a long time, which you have a lot of.

Logging out

Dale
2  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 28, 2013, 06:10:58 pm
This forum is for help and is unique from all others I have used, in that the amount of comments posted that are unhelpful. If somebody asks for a hint then give them a hint, it's that simple. but most on here are noobs asking for help.
Quote
You need to remember that the pay here isn't all that great. We're all volunteers. Sometimes that works; sometimes it doesn't.

If the project is important to you, and is beyond your skill set, you have two choices. Expand your skill set (learn!) or head over to Gigs and Collaboration, and offer to pay for the help you need.

 I've got a few "how to" videos on youtube machining related, but I'm not asking a payment for them, just done it to help others. This is what makes the internet great, expanding people's minds.

Regards

Dale
3  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 28, 2013, 05:42:34 pm
Thanks for all the people that have helped (mainly John) on this project and those that have been less than, why bother posting a reply. I did try to get the button code working but it's way beyond me, After researching around I found the best example was in the examples/digital/state change detection. I did try and hack this code into my prog but have admitted defeat.

Kind regards

Dale
4  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 26, 2013, 11:22:03 am
Oops

 I have'nt been doing a good job on my comments,I was going to tidy them when I got a finally rev of the program but can see this one is misleading.
Quote
float pos = 0;    // variable to store the rotary switch input
now reads
Quote
float pos = 0;    // variable for servo positon

regards

Dale
5  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 26, 2013, 11:11:05 am
John thanks for the second link, I've done a copy and paste
Quote
Here is an example of countdown using a for loop:
 




1234567891011
// countdown using a for loop
#include <iostream>
using namespace std;
int main ()
{
  for (int n=10; n>0; n--) {
    cout << n << ", ";
  }
  cout << "FIRE!\n";
  return 0;
}
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, FIRE!



I don't think there is a better way to learn then to see an example of how its done.
Here is my working code: with better comments
Code:
#include <Servo.h>

Servo myservo1;  // create servo object to control a servo
// a maximum of eight servo objects can be created

float pos = 0;    // variable to store the rotary switch input



void setup() {
  myservo1.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo1.write(pos);
  delay(3000);
}

// the loop routine runs over and over again forever:
void loop() {

  int sensorValue = analogRead(A0); // read value from rotary switch
  if (sensorValue > 100 && sensorValue < 200) // rotary switch position 1
  {


    // rise and fall code                      
    for (pos = 12.5; pos < 18; pos += .1){  // goes from 12.5  to 15
      // in steps of .1  
      myservo1.write(pos);              // tell servo to go to position in variable 'pos'
      delay(25);                       // waits 15ms for the servo to reach the position
    }

    delay(3000);

    for (pos = 18; pos>=12.5; pos-=.1) {    // goes from 15  to 12.5  

      myservo1.write(pos);              // tell servo to go to position in variable 'pos'
      delay(25);     // waits 15ms for the servo to reach the position
    }
  }
  else if (sensorValue > 200 && sensorValue < 400) // rotary switch position 2
  {
    pos=13;
  }
  else if (sensorValue > 400 && sensorValue < 600) {// rotary switch position 3
    pos=14;
  }  
  else if (sensorValue > 600 && sensorValue < 700) {// rotary switch position 4
    pos=15;
  }
  else if (sensorValue > 700 && sensorValue < 900) {// rotary switch position 5
    pos=16;
  }
  else if (sensorValue > 900) {// rotary switch position 6
    pos=17;
  }


  myservo1.write(pos);

}


I really happy with how the program is coming along, due to all the help I have recieved. Next thing on my to do list is wire the switches to my breadboard and start experimenting.

John I was looking Jeremy Blum vid on youtube and seen a familiar name in the recommendations John NYCCNC is that you?
I've subscribed anyway, lots of very interesting vids to look at. I am a cnc'er myself, I've got a small vmc which I also use to turn small parts on which is what I made the air raid on, I've also biult my own router table.

Regards

Dale
6  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 26, 2013, 10:02:16 am
Hi paul

I'll post the entire code below
Code:
#include <Servo.h>

Servo myservo1;  // create servo object to control a servo
// a maximum of eight servo objects can be created

float pos = 0;    // variable to store the rotary switch input



void setup() {
  myservo1.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo1.write(pos);
  delay(3000);
}

// the loop routine runs over and over again forever:
void loop() {

  int sensorValue = analogRead(A0);
  if (sensorValue > 100 && sensorValue < 200)
  {
   // pos=12.5;

    // rise and fall code                     
    for (pos = 12.5; pos < 18; pos += .1)  // goes from 12.5  to 18
                                                          // in steps of .1 
      myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(25);                       // waits 15ms for the servo to reach the position


    delay(1000);

    for (pos = 18; pos>=12.5; pos-=.1)     // goes from 18  to 12.5 

      myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(25);                       // waits 15ms for the servo to reach the position
  }

  else if (sensorValue > 200 && sensorValue < 400) // error on this line
  {
    pos=13;
  }
  else if (sensorValue > 400 && sensorValue < 600) {
    pos=14;
  } 
  else if (sensorValue > 600 && sensorValue < 700) {
    pos=15;
  }
  else if (sensorValue > 700 && sensorValue < 900) {
    pos=16;
  }
  else if (sensorValue > 900) {
    pos=17;
  }


  myservo1.write(pos);

}


Pos is a float as I want more control over the rise and fall of my motor


Quote
Well, you ought to have them, even if they are not strictly needed. Having them makes them look like you know what you are doing.

If you didn't add this comment, why have you ignored it?

The other code has some braces that you need and some that you do not. You need to learn to tell the difference.

I don't think I explained it very well, originally I had it with braces but I got an error with my else before if statement, to get the program to compile as john pointed out i need to place all the rise a fall code in between the braces. but this causes the program to loop the  rise and fall part between the braces.

Regards

Dale

P.S. John just posted as i was writing this, cheers I'll check those links out right now
7  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 26, 2013, 09:00:06 am
Hi,

I thought I had it sorted when I testing last night, the wife was giving me the evil eye on testing the siren so late. turns out that it is not rising and falling. I think it's due to it doing everthing between the braces which is increment up .1  then delay and then increment down .1 which keeps the speed the same, which is whats happining. I posted the code below with better coments
Code:
void loop() {

  int sensorValue = analogRead(A0);
  if (sensorValue > 100 && sensorValue < 200)
  {
   

    // rise and fall code                     
    for (pos = 12.5; pos < 18; pos += .1)  // goes from 12.5  to 12.6
            myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(25);                       // waits 15ms for the servo to reach the position
// because there is no braces code does not loop and reach pos 18, but moves onto next line

    delay(1000);

    for (pos = 18; pos>=12.5; pos-=.1)     // this one is odd as I should hear it jump from 12.6 to 18
                                                           //  but it seems a constant speed, no change in sound anyway

      myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(25);                       // waits 15ms for the servo to reach the position
  }                                       // loop back

 

I went back to I to an old program just to check it worked with the braces and it did code below.
Code:
void loop()
{

  for(pos = 12.5; pos < 18; pos += .1)  // goes from 12.5 degrees to 18 degrees in .1 increments
  {                                 
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15    );      // waits 15ms for the servo to reach the position
  }
// loop until pos = 18
  {

    delay (5000); 

  }
  for(pos = 18; pos>=12.5; pos-=.1)     // goes from 18  to 12.5  in .1 increments
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
// loop until pos = 12.5
}


Am I on the right lines in my thinking, seems it's a formatting error but I don't know the correct format. Any information gratefully recieved

Regards

Dale
8  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 25, 2013, 06:53:22 pm
Thanks John,

Code modified and running ok, much appreciated.

Hazzard thanks for the upload, I was thinking more of a count then time based, but thinking more about it, if i did go down the count method I would need to have a way to re-set the counter and time based is maybe the way to go. Hmm my hurts. I need to wire these switches to my breadboard and start experimenting.

Regards

Dale
9  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 25, 2013, 04:07:54 pm
Hi,

 I've modified my code without the goto's and the program is working ok
Code:
#include <Servo.h>

Servo myservo1;  // create servo object to control a servo
// a maximum of eight servo objects can be created

float pos = 0;    // variable to store the rotary switch input



void setup() {
  myservo1.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo1.write(pos);
  delay(3000);
}

// the loop routine runs over and over again forever:
void loop() {

  int sensorValue = analogRead(A0);
  if (sensorValue > 100 && sensorValue < 200) {
    pos=10;
  }
  else if (sensorValue > 200 && sensorValue < 400) {
    pos=13;
  }
  else if (sensorValue > 400 && sensorValue < 600) {
    pos=14;
  } 
  else if (sensorValue > 600 && sensorValue < 700) {
    pos=15;
  }
  else if (sensorValue > 700 && sensorValue < 900) {
    pos=16;
  }
  else if (sensorValue > 900) {
    pos=17;
  }


  myservo1.write(pos);

}


But then I added a basic rise and fall code for the first rotary switch position but get the error:
_13_prog.cpp: In function 'void loop()':
_13_prog:44: error: 'else' without a previous 'if'

I removed the else and the code compiled, but when I tested the air raid it only ran the rise and fall code and not the other switch positions
Code:
#include <Servo.h>

Servo myservo1;  // create servo object to control a servo
// a maximum of eight servo objects can be created

float pos = 0;    // variable to store the rotary switch input



void setup() {
  myservo1.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo1.write(pos);
  delay(3000);
}

// the loop routine runs over and over again forever:
void loop() {

  int sensorValue = analogRead(A0);
  if (sensorValue > 100 && sensorValue < 200)
   {
    pos=12.5;
  }
  // rise and fall code                     
  for(pos = 12.5; pos < 15; pos += .1)  // goes from 12.5  to 15
  {                                  // in steps of .1 
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(25);                       // waits 15ms for the servo to reach the position
  }

  delay(5000);

  for(pos = 15; pos>=12.5; pos-=.1)     // goes from 15  to 12.5
  {                               
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(25);                       // waits 15ms for the servo to reach the position
  }


   else if (sensorValue > 200 && sensorValue < 400) // error on this line
  {
    pos=13;
  }
  else if (sensorValue > 400 && sensorValue < 600) {
    pos=14;
  } 
  else if (sensorValue > 600 && sensorValue < 700) {
    pos=15;
  }
  else if (sensorValue > 700 && sensorValue < 900) {
    pos=16;
  }
  else if (sensorValue > 900) {
    pos=17;
  }


  myservo1.write(pos);

}



Where am I going wrong with this piece of code? Any infomation would be gratefully recieved

Regards

Dale
10  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 23, 2013, 04:11:54 pm
I was gratfully for the post but i was beening honest in my knowlege, I will do some research on the posted code after I re write my program.

Regards

Dale.
11  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 23, 2013, 03:48:58 pm
Thanks des,

Thats a lot above my ability right now, I think i can make out it's altering the delay of the led based on the the button couter. hard for me to understand without the comment lines.

Kind regards

Dale
12  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 23, 2013, 11:20:48 am
Thanks John,

 Yes I do need a hint, I think understand the code you posted,  I'll do a re write and post it back here.

Kind regards

Dale
13  Using Arduino / Programming Questions / Re: different action based on the number of times a button is pressed on: January 22, 2013, 05:59:06 pm
I am happy with my motor control, it runs,  I can controller it's rise and fall with great precision. John thanks you have been most helpfull and have explained the best way to write my else if statements I did pre check the analog values before doing my else if statements 168/339/509/680/852/1023.

Kind regard

Dale
14  Using Arduino / Programming Questions / different action based on the number of times a button is pressed on: January 22, 2013, 05:05:45 pm
Hi,

I'm getting close to finishing my air raid siren ( see attached photo's )  I've written some code to alter the siren speed depending the position of a rotary switch, this took me a while using the arduino cook book, Jeremy Blum vids on youtube and here searching the forums.

My setup is RC motor and controller with BEC, 7.2v 3700mah battery, arduino uno, 6 position rotary switch with voltage divider circuit to sense position, main power on / off switch, on order two led push buttons.

I've got the siren running on this set up but would like to add 2 NO push buttons in series to start the siren. this is a safety feature to ensure both hands are on the buttons when running. ( and not in the chopper )

The first three positions on the rotary switch will be low speed cycles for indoor use for me and my kid to use. the remaining three postion will be full speed simulating WWII air raid, and fire trucks but I don't want the little guy hurting his ears so I was thinking of creating a pushing pattern to enable the high speed cycles. something like 5 short presses on the push buttons.

This is where i need some help in formating the right code into my program. my thoughts are sense the button being pressed add 1 to variable each time it's pressed then i need to add this to my else if statements but I not sure of the correct formatting.

Any help would gratefully recieved, please go gently on my code as this is the 1st arduino program I've written, I'm sure it could be more efficient,  but the only other thing I've programmed is a 1970's Casio calculator for trigonometry.
 
Regards

Dale

Code:
#include <Servo.h>

Servo myservo1;  // create servo object to control a servo
// a maximum of eight servo objects can be created

float pos = 0;    // variable to store the rotary switch input



void setup() {
  myservo1.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo1.write(pos);// arm speed controller
  delay(3000);
}

// the loop routine runs over and over again forever:
void loop() {
  
  start:
  int sensorValue = analogRead(A0);  // read the input on analog pin 0:
  if (sensorValue > 100 && sensorValue < 200) { goto servo1;}     // create jump to values
  else if (sensorValue > 300 && sensorValue < 400) { goto servo2;}
  else if (sensorValue > 500 && sensorValue < 599) { goto servo3;}
  else if (sensorValue > 600 && sensorValue < 699) { goto servo4;}
  else if (sensorValue > 800 && sensorValue < 899) { goto servo5;}
  else if (sensorValue > 900) { goto servo6;}
  
  

  servo1:
   {                                 // MAX SPEED 120
      myservo1.write(pos = 10);              // tell servo to go to position in variable 'pos'
   }  
  { goto start;}
  
  servo2:
   {                                
     myservo1.write(pos = 13);  
   }
  { goto start;}
  
   servo3:
    {                                
      myservo1.write(pos = 20);              // tell servo to go to position in variable 'pos'
   }  
  { goto start;}
  
  servo4:
  {                                
      myservo1.write(pos = 25);              // tell servo to go to position in variable 'pos'
   }  
  { goto start;}
  servo5:
 {                              
      myservo1.write(pos = 30);              // tell servo to go to position in variable 'pos'
   }  
  { goto start;}
  
  servo6:
  {                                
       myservo1.write(pos = 120);              // tell servo to go to position in variable 'pos'
      //delay(700);
                    
   }  
  { goto start;}

}

15  Using Arduino / Project Guidance / Re: stepper driven mechanical clock with RTC on: January 08, 2013, 07:25:46 pm
Hi,

Yes I think this is the route I'll take ( transmissive beam ), still in the design stage so I need to finalize my designs

Many thanks

Dale
Pages: [1] 2