Show Posts
Pages: 1 [2]
16  Using Arduino / Programming Questions / Get the push button sense once on: February 09, 2013, 10:26:36 am
I'm using the push button with the built in pull-up resistor;

pinMode(b1, INPUT_PULLUP);

and have such a main loop. Whenever I press the push button and hold, the empty string called "pass" takes dozens of "1", as expected smiley
However I want to make it sense the push once until I release it and push again.
By that structure, it is not likely to implement I think.

What would your suggestions be ?

void loop()
{
  if(digitalRead(b1) == LOW)
  {
    pass += "1";
    counter += 1;
  }
}
17  Using Arduino / Displays / Re: 7 Segment connection and code on: February 09, 2013, 08:12:33 am
Did you try setting any of the output pins HIGH?

Are you sure your displays are Common Cathode?

Yes I've tried both High and low
18  Using Arduino / Displays / Re: 7 Segment connection and code on: February 09, 2013, 08:06:11 am
Okay I've realised one of the problems.

pinMode declarations had to be as follows

pinMode(a, OUTPUT) and goes like that.

However, still nothing happens.
19  Using Arduino / Displays / 7 Segment connection and code on: February 09, 2013, 07:44:34 am
Connected the middle pins both at the up and bottom to ground, a,b,c,d,e,f,g are connected to outputs as well. (didn't use any resistor for a,b,c... but GND)

The code is quite straightforward but didn't work don't know why ? At where am I wrong ?
Quote
int a = 8;
int b = 9;
int c = 10;
int d = 11;
int e = 12;
int f = 13;
int g = 7;

void setup()
{
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(7, OUTPUT);
}
void loop()
{
  digitalWrite(a, LOW);
}
20  Using Arduino / Sensors / Re: Angular position measuring on: February 05, 2013, 09:14:45 pm
A potentiometer would probably be easiest if you can find one that's durable enough and allows continuous rotation.

A couple links for fairly inexpensive encoders:

http://www.usdigital.com/products/encoders/absolute/rotary
http://www.cui.com/Product/Components/Encoders/Absolute_Encoders/Modular/AMT203-V

There are also ICs (e.g. AS5030) that will sense the rotational position of a magnet placed over them. Offhand I can't seem to find any retail breakouts for them. The least expensive option but also the most difficult to implement.

Do I need an encoder as I am using potentiometer ?
21  Using Arduino / Sensors / Angular position measuring on: February 03, 2013, 08:23:01 pm
Planning to built an inverted pendulum. However, don't know how to measure the angular position of the pendulum (even not sure if measuring the angular position is the best option to control such a system).

Using a gyroscope sounds good but just wanted to get your opinions.
What would your solution be ?
22  Using Arduino / Programming Questions / Re: LED brightness control on: January 31, 2013, 04:25:52 pm
Here's my try:

Connect a SPST N.O. momentary from pin 8 to GND with no resistor.
Connect an LED from pin 9 to an LED in series with a current-limiting resistor (220 to 330 ohm) to GND.

My code:
Code:
int but = 8;
int led = 9;
int val = 0;

void setup()
{
  pinMode(but, INPUT_PULLUP);
  pinMode(led, OUTPUT);             // not needed, but I like to be explicit
}

void loop()
{
  if(digitalRead(but) == LOW)
  {
    //here: the button is pushed
     val += 20;                                 // increment the brightness of the LED by 1/24th
    val = min(val, 255);                     // maximum PWM value is 255
  }
  else
  {
    //here: the button has been released
    val = 0;                                  // turn the LED OFF
  }

  analogWrite(led,val);                 // adjust the PWM
  delay( 250 );                           // give yourself a chance to see the result
}

should take about 3 seconds from OFF to full brightness. If you need it to be quicker, adjust the delay time
the delay also tends to debounce the switch too

After inspected the code, I realised that you also used "LOW" for if statement with buttons. Why is it so ?
I think if the button is not pushed it should be act as "LOW" and the led starts shining, but it doesn't and the code works pretty well.
But didn't get the idea underlying.

Suppose found my answer;

"Because the internal pull-up on pin 2 is active and connected to 5V, we read HIGH when the button is open"
23  Using Arduino / Programming Questions / Re: LED brightness control on: January 31, 2013, 04:23:22 pm
Here's my try:

Connect a SPST N.O. momentary from pin 8 to GND with no resistor.
Connect an LED from pin 9 to an LED in series with a current-limiting resistor (220 to 330 ohm) to GND.

My code:
Code:
int but = 8;
int led = 9;
int val = 0;

void setup()
{
  pinMode(but, INPUT_PULLUP);
  pinMode(led, OUTPUT);             // not needed, but I like to be explicit
}

void loop()
{
  if(digitalRead(but) == LOW)
  {
    //here: the button is pushed
     val += 20;                                 // increment the brightness of the LED by 1/24th
    val = min(val, 255);                     // maximum PWM value is 255
  }
  else
  {
    //here: the button has been released
    val = 0;                                  // turn the LED OFF
  }

  analogWrite(led,val);                 // adjust the PWM
  delay( 250 );                           // give yourself a chance to see the result
}

should take about 3 seconds from OFF to full brightness. If you need it to be quicker, adjust the delay time
the delay also tends to debounce the switch too

After inspected the code, I realised that you also used "LOW" for if statement with buttons. Why is it so ?
I think if the button is not pushed it should be act as "LOW" and the led starts shining, but it doesn't and the code works pretty well.
But didn't get the idea underlying.
24  Using Arduino / Programming Questions / Re: LED brightness control on: January 31, 2013, 04:00:32 pm
Here's my try:

Connect a SPST N.O. momentary from pin 8 to GND with no resistor.
Connect an LED from pin 9 to an LED in series with a current-limiting resistor (220 to 330 ohm) to GND.

My code:
Code:
int but = 8;
int led = 9;
int val = 0;

void setup()
{
  pinMode(but, INPUT_PULLUP);
  pinMode(led, OUTPUT);             // not needed, but I like to be explicit
}

void loop()
{
  if(digitalRead(but) == LOW)
  {
    //here: the button is pushed
     val += 20;                                 // increment the brightness of the LED by 1/24th
    val = min(val, 255);                     // maximum PWM value is 255
  }
  else
  {
    //here: the button has been released
    val = 0;                                  // turn the LED OFF
  }

  analogWrite(led,val);                 // adjust the PWM
  delay( 250 );                           // give yourself a chance to see the result
}

should take about 3 seconds from OFF to full brightness. If you need it to be quicker, adjust the delay time
the delay also tends to debounce the switch too

Thank you, that one worked, but I didn't know input_pullup thing.

Ok those need to be debounced to work properly. So even if you just press it once, being that it is not being debounce, it will put out a LOT of noise. Meaning even if YOU press it once, the arduino will see that it was pressed multiple times, because of that noise. Also did you include a pulling resistor?

Don't know what pulling resistor is
What exactly is it ?
25  Using Arduino / Programming Questions / Re: LED brightness control on: January 31, 2013, 03:47:03 pm
Quote
However, it immediately starts trebling.
Even without the button being pressed? Does your button have a pull down or up resistor?
Code:
if(digitalRead(but) == 1)
This is looking for the button to be HIGH when pressed, so if you have a floating input (no pulling resistor), that would cause the flicker.

The button I have is that;
26  Using Arduino / Programming Questions / Re: LED brightness control on: January 31, 2013, 03:29:34 pm
But at least at the beginning the led must not shine, right ?
However, it immediately starts trebling.
27  Using Arduino / Programming Questions / LED brightness control on: January 31, 2013, 03:09:28 pm
Have just got the arduino and trying some simple things on it, here one of them;
I want to increase the brightness of the LED 20 unit each time I press the push button, quite simple.
However, It doesn't work, the LED light tremble and when I push the button it stops trembling.

Here's the code;

Quote
int but = 8;
int led = 9;
int val = 0;

void setup()
{
  pinMode(but, INPUT);
  pinMode(led, OUTPUT);
}

void loop()
{
  if(digitalRead(but) == 1)
  {
    val = val + 20;
  }
  analogWrite(led,val);
}
Pages: 1 [2]