basic button issue on VE

Store Forums Video Experimenter Bugs/Problems basic button issue on VE

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #9587
    ronen
    Participant

    I’m really rusty with this but I’m just trying to see how to make the VE respond to a basic button call. I’ve no idea what I’m missing. I got an Arduino Duemilanove & the VE shield, preassembled. I’ve made it make a really nice display but for some reason can’t get a button to work even though I’ve done the basic button tutorial (https://www.arduino.cc/en/tutorial/button).

    What’s showing on the monitor is an initial flicker and then it’s dead.

    Also, I couldn’t get the onboard ledPin to light up with the shield either.

    #include <TVout.h>
    #include <video_gen.h>
    
    TVout TV;
    
    // constants won't change. They're used here to set pin numbers:
    const int buttonPin = 5;     // the number of the pushbutton pin
    
    // variables will change:
    int buttonState = 0;         // variable for reading the pushbutton status
    
    void setup() {
      // put your setup code here, to run once:
      TV.begin(NTSC,120,96);
      initOverlay();
      
      // initialize the pushbutton pin as an input:
      pinMode(buttonPin, INPUT);
    }
    void initOverlay() {
      TCCR1A = 0;
      // Enable timer1.  ICES0 is set to 0 for falling edge detection on input capture pin.
      TCCR1B = _BV(CS10);
    
      // Enable input capture interrupt
      TIMSK1 |= _BV(ICIE1);
    
      // Enable external interrupt INT0 on pin 2 with falling edge.
      EIMSK = _BV(INT0);
      EICRA = _BV(ISC01);
    }
    
    // Required to reset the scan line when the vertical sync occurs
    ISR(INT0_vect) {
      display.scanLine = 0;
    }
    
    void loop() // put your main code here, to run repeatedly:
    {
      // 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) {
        TV.println("buttonState == HIGH");
      } else {
        TV.println("buttonState == LOW");
      }
    }

    Any advice would be great! Afterwards I want to add a few pots to the design but that should be easy since I got that working on the older TVout library. Thanks!

    #9588
    Michael
    Keymaster

    Here’s a couple hints. First, put a delay inside of loop() so you are not running that code as fast as you can. For example, add “delay(100);” so you only read the button and print 10 times a second. That should be plenty. Maybe even delay longer than 100ms.

    Next, I’m not sure if there is a wiring problem with your button, but an easier way to use a button is to declare the pin as INPUT_PULLUP instead of INPUT, and just wire the button so that when you close it, it connects the digital input to ground. The wiring is simpler, there’s no resistor, and no significant current flows in the button circuit. Pin mode INPUT_PULLUP sets the pin to HIGH and uses an internal resistor. When the pin is connected to ground, it will read LOW.

    #9589
    ronen
    Participant

    Thanks for your quick response! However…

    Tried both the delay(100) and the INPUT_PULLUP with a simpler button layout with no luck 🙁
    Even tried adding a much longer delay of delay(500).

    Argh

    #9590
    Michael
    Keymaster

    Try this. You need to import the fonts and set the font for printing to work. Also using TV.delay(500) works better than delay(500).

    
    #include <TVout.h>
    #include <fontALL.h>
    #include <video_gen.h>
    
    TVout TV;
    
    // constants won't change. They're used here to set pin numbers:
    const int buttonPin = 5;     // the number of the pushbutton pin
    
    // variables will change:
    int buttonState = 0;         // variable for reading the pushbutton status
    
    void setup() {
      // put your setup code here, to run once:
      TV.begin(NTSC,120,96);
      initOverlay();
      TV.select_font(font6x8);
      TV.fill(0);
      
      // initialize the pushbutton pin as an input:
      pinMode(buttonPin, INPUT_PULLUP);
    }
    void initOverlay() {
      TCCR1A = 0;
      // Enable timer1.  ICES0 is set to 0 for falling edge detection on input capture pin.
      TCCR1B = _BV(CS10);
    
      // Enable input capture interrupt
      TIMSK1 |= _BV(ICIE1);
    
      // Enable external interrupt INT0 on pin 2 with falling edge.
      EIMSK = _BV(INT0);
      EICRA = _BV(ISC01);
    }
    
    // Required to reset the scan line when the vertical sync occurs
    ISR(INT0_vect) {
      display.scanLine = 0;
    }
    
    void loop() // put your main code here, to run repeatedly:
    {
      TV.delay(500);
      // 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) {
        TV.println("buttonState == HIGH");
      } else {
        TV.println("buttonState == LOW");
      }
    }
    
    #9592
    ronen
    Participant

    YES! It just needed the <fontALL.h> and the TV.select_font(font6x8). I took out the delay and I realized that I left the pinMode at just “INPUT”

    I knew it was something easy that I forgot! Thank you 🙂

    • This reply was modified 6 years, 7 months ago by ronen.
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.