Show Posts
Pages: 1 2 3 [4] 5 6 ... 27
46  Using Arduino / Programming Questions / Re: Array problem , 3buttons and three leds on: February 03, 2013, 09:56:31 am
try making this part as an array too
Code:
boolean LedState =LOW;
int SwitchDebounce;
int LastSwitchState=HIGH;
int LastSwitchDebounce=LOW;
unsigned long LastDebounceTime = 0;

because all this can only hold info for one switch, more then that you need a way to hold all that info
47  Using Arduino / Programming Questions / Re: Multiple Blink States with a button no delay on: February 03, 2013, 09:52:37 am
PaulS, My real code is in reply #6,
what it does, well it work flawlessly for switch statement from 0-2 but  then it go to case 3, something weird happen, it does not follow the pattern that was set thru array pattern 3, it just goes blinking randomly. other then that theres s few thing that bothering me, i know that array pattern2 have only 4 state but in the case 2 i have to make it as though if count==6 to become 0 only then will the program for case 2 work flawlessly
48  Using Arduino / Programming Questions / Re: Traffic Light Programming help on: February 03, 2013, 08:17:48 am
it is mostly base of preference, but as PaulS point out its better to start counting from 0/1 up to what ever number you have to give the variable name. but usually for me, if i have to use the same variable name nowadays i would utilize array to keep all the info
49  Using Arduino / Programming Questions / Re: Array problem , 3buttons and three leds on: February 03, 2013, 08:14:59 am
try this code but change all the variable to become array

Code:
uint8_t Switch = 2;
uint8_t Led =13;

boolean LedState =LOW;
int SwitchDebounce;
int LastSwitchState=HIGH;
int LastSwitchDebounce=LOW;

unsigned long LastDebounceTime = 0;
unsigned long DebounceDelay = 50;

void setup()
{
  pinMode(Switch,INPUT);
  digitalWrite(Switch,HIGH);
  pinMode(Led,OUTPUT);
}

void loop()
{
  int CurrentSwitch = digitalRead(Switch);
  if (CurrentSwitch != LastSwitchDebounce)
  {
    LastDebounceTime = millis();
  }
  if ((millis() - LastDebounceTime) > DebounceDelay)
  {
    if (CurrentSwitch != LastSwitchState)
    {
      if (CurrentSwitch == LOW)
      {
        LedState = !LedState;
      }
    }
    LastSwitchState=CurrentSwitch;
  }
  digitalWrite(Led,LedState);
  LastSwitchDebounce = CurrentSwitch;
}
for one switch it does the work well to make for input internal pull up, debounce and State Change detection. and it does what you want for one Switch, if you need it to work for 3 modify this to suit ur need
50  Using Arduino / Programming Questions / Re: Initiallizing local variables on: February 03, 2013, 08:09:09 am
now i know what static does, so this way i do not need to declare to may global variable now huh.
51  Using Arduino / Programming Questions / Re: Initiallizing local variables on: February 03, 2013, 08:04:27 am
Sorry AWOL if i'm not clear with my question, I want to know if i could initialize Count variable as a local variable inside the void loop()?
i what the value to be the last value that it has b4 the loop function loop around, i dont want it to be reset back to 0.
52  Using Arduino / Programming Questions / Re: Array problem , 3buttons and three leds on: February 03, 2013, 08:01:39 am
you could choose to make 2 array for Val and OldVal respectively or if you know how to use Struct in C++ you could make 1 array to hold both value.
53  Using Arduino / Programming Questions / Initiallizing local variables on: February 03, 2013, 07:59:36 am
guys i was wondering about local variable
my question is something like this
I always and i mean almost always initialize my variable to be a global variable, but i was wondering could i initiate it in someway so it to become a local variable
heres an example:
Code:
int Count=0;
void setup()
{ yada yada yada}
void loop()
{
 did something heres that causes
  Count++;
}

but could somehow i want it to be like this

Code:
void loop()
{
  int Count=0;
somthing happen somwhere here
and then Count++;
}

i know that if i do it as the second way that is initializing the Count in the loop section will make the Count value reset to 0 every time it loop
54  Using Arduino / Programming Questions / Re: Array problem , 3buttons and three leds on: February 03, 2013, 07:50:38 am
a few more advice,
debounce and StateChange detection will do wonders for your program
55  Using Arduino / Programming Questions / Re: Array problem , 3buttons and three leds on: February 03, 2013, 07:43:06 am
how do you connect the wire for the switches and LEDs?
do you have a pull-up/down for your switches?
what you want your program to do are:
if Switch1 is press,LED1 light up, press the Switch1 again, LED1 turn off?
if Switch2 is press,LED2 light up, press the Switch2 again, LED2 turn off?
if Switch3 is press,LED3 light up, press the Switch3 again, LED3 turn off?

you have set all the Switch and LED in 2 array respectively
but you forget to put an array towards SwitchState and LedState.
56  Using Arduino / Programming Questions / Re: Simple LED Blink code, Kinda.... on: February 03, 2013, 07:36:32 am
what is blink in your definition?
57  Using Arduino / Programming Questions / Re: Simple button counter that increments by 5 on: February 03, 2013, 07:34:23 am
welcome.

i think among a few thing that people should know when starting o learn how to program arduino is the blink without delay , debounce and state change... and flag based programming . this all have a powerful effect toward solving most problem
58  Using Arduino / Programming Questions / Re: Simple button counter that increments by 5 on: February 03, 2013, 07:00:47 am
this part
Code:
int Counter=0;
change to this
Code:
int Counter=5;
59  Using Arduino / Programming Questions / Re: Simple button counter that increments by 5 on: February 03, 2013, 06:06:31 am
try this, its my code, see how i did the press thing
Code:
uint8_t Switch = 2;
uint8_t Led =13;

boolean LedState =LOW;
int SwitchState =0;
int SwitchDebounce;
int LastSwitchState=HIGH;
int LastSwitchDebounce=LOW;
int Counter=0;

unsigned long LastDebounceTime = 0;
unsigned long DebounceDelay = 50;

void setup()
{
  pinMode(Switch,INPUT);
  digitalWrite(Switch,HIGH);
  pinMode(Led,OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  int CurrentSwitch = digitalRead(Switch);
  if (CurrentSwitch != LastSwitchDebounce)
  {
    LastDebounceTime = millis();
  }
  if ((millis() - LastDebounceTime) > DebounceDelay)
  {
    if (CurrentSwitch != LastSwitchState)
    {
      if (CurrentSwitch == LOW)
      {
        Counter=Counter+5;
        Serial.println(Counter);
      }
    }
    LastSwitchState=CurrentSwitch;
  }
  LastSwitchDebounce = CurrentSwitch;
}
60  Using Arduino / Programming Questions / Re: Simple button counter that increments by 5 on: February 03, 2013, 05:32:48 am
my advice would be lose the delay and use the method underline in blink without delay.
the other thing is to debounce the switch
Pages: 1 2 3 [4] 5 6 ... 27