Pages: [1]   Go Down
Author Topic: Playground Switch tutorial not clear  (Read 390 times)
0 Members and 1 Guest are viewing this topic.
London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mellis, I was going to point someone to the switch tutorial in the playground , but I found that tutorial really confusing.

The first problem is that the wiring diagram is confusing. Its unclear which pins the  wires go to on the arduino and it's not very clear what that resistor is connected to.

And it looks from the diagram like the pin would be normally high, pulled low when pressed but the text says the opposite happens.

Another issue may just be with choice of example. I think it would be difficult for the target audience to figure out how to do a non toggling version from the example code. A simple debounce of on and off would probably be used at least as much as a toggle.
« Last Edit: August 08, 2008, 01:07:26 pm by mem » Logged

Las Vegas, NV
Offline Offline
God Member
*****
Karma: 0
Posts: 507
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Also, the switch tutorial would be a great place to show people how to use a pin's internal pull-up resistor.  A button circuit for the AVR can be as simple as simply connecting a pin through a button to ground, but most tutorials I see make a big deal about using an external resistor in the circuit, which tends to complicate things and doubles the number of required components.

- Ben
Logged


London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Also, the switch tutorial would be a great place to show people how to use a pin's internal pull-up resistor.  A button circuit for the AVR can be as simple as simply connecting a pin through a button to ground, but most tutorials I see make a big deal about using an external resistor in the circuit, which tends to complicate things and doubles the number of required components.

- Ben
Yes, but  dealing with pull-ups  is one extra concept that would need  to be grasped by someone just starting out.  Having the physical resistor in a basic tutorial helps people new to electronics visualize what is happening. I suggest pull-ups are covered after the basic switch with resistor is explained.
« Last Edit: August 08, 2008, 01:33:16 pm by mem » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How about a 2 or more part tutorial via links.  Progressive learning is easy when there are links on where to go next to expand on the current topic.
Logged

Bangkok, Thailand
Offline Offline
Newbie
*
Karma: 0
Posts: 47
Arduino POP!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd currently use below code for switch tutorial, step-by-step coding and clear.

Code:
/*
  Toggle LED (13 active-high) with Push Button switch (2 active-low)
 */

int swPin = 2;
int ledPin = 13;
int ledState = 0; // intial state = 0

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(swPin, INPUT);
  digitalWrite(swPin, HIGH); // enable internal pull-up (Ext. R may removed)
}

void loop()
{
  if ((digitalRead(swPin))==LOW) // switch is pressed?
 {
    if (ledState==0)  // toggle state and led acion
    {
      digitalWrite(ledPin,HIGH);
      ledState=1;
    }
    else
    {
      digitalWrite(ledPin,LOW);
      ledState=0;
    }

    while ((digitalRead(swPin))==LOW) // wait for switch depressed
    { delay(10); }
 }
}

or another code without waiting

Code:
/*
  Toggle LED (13 active-high) with Push Button switch (2 active-low)
 */

int swPin = 10;
int ledPin = 13;
int ledState = 0; // intial state = 0
int swPressed = 0; // sw hold state =0
void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(swPin, INPUT);
  digitalWrite(swPin, HIGH); // enable internal pull-up (Ext. R may removed)
}

void loop()
{
  if ((digitalRead(swPin))==LOW) // switch is pressed?
  {
    if (swPressed==0)
    {
      swPressed=1;
      delay(10);
      if (ledState==0)  // toggle state and led acion
      {
        digitalWrite(ledPin,HIGH);
        ledState=1;
      }
      else
      {
        digitalWrite(ledPin,LOW);
        ledState=0;
      }
    }
  }
  else
  {
    swPressed=0;
  }
}

« Last Edit: August 09, 2008, 02:18:55 pm by worapoht » Logged

Austin, TX
Offline Offline
Full Member
***
Karma: 1
Posts: 182
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd suggest the ladyada Arduino tutorial Lesson 5. It is very basic, step by step and has clear schematics and diagrams.
http://www.ladyada.net/learn/arduino/lesson5.html

Would it be out of line to link to this from the playground?
Logged

Chris J. Kiick
Robot builder and all around geek.

Pages: [1]   Go Up
Jump to: