Snowball Throwing Target Project


the idea of project have target act button or trigger lighting response when target hit. i've been toying mega 2560 picked other day, , have been able run few of sample sketch codes, relative ones being "button" , "blink without delay." think need use relay shield this: http://www.freetronics.com.au/collections/shields/products/relay8-8-channel-relay-driver-shield#.vhpda_lvhhw , switch this: https://www.sparkfun.com/products/10747 plug led floodlight , make flash designated amount of time when button pressed being struck snowball. on rigth track? did of direction video: https://www.youtube.com/watch?v=dvaim22wyhy&noredirect=1
 

i've been trying unsuccessfully merge this:
code: [select]

// constants won't change. they're used here to
// set pin numbers:
const int buttonpin = 2;     // number of pushbutton pin
const int ledpin =  13;      // number of led pin

// variables change:
int buttonstate = 0;         // variable reading pushbutton status

void setup() {
  // initialize led pin output:
  pinmode(ledpin, output);
  // initialize pushbutton pin input:
  pinmode(buttonpin, input);
}

void loop() {
  // read state of pushbutton value:
  buttonstate = digitalread(buttonpin);

  // check if pushbutton pressed.
  // if is, buttonstate high:
  if (buttonstate == high) {
    // turn led on:
    digitalwrite(ledpin, high);
  }
  else {
    // turn led off:
    digitalwrite(ledpin, low);
  }
}
code: [select]


// constants won't change. used here set pin number :
const int ledpin =  13;      // number of led pin

// variables change :
int ledstate = low;             // ledstate used set led

// generally, should use "unsigned long" variables hold time
// value become large int store
unsigned long previousmillis = 0;        // store last time led updated

// constants won't change :
const long interval = 1000;           // interval @ blink (milliseconds)

void setup() {
  // set digital pin output:
  pinmode(ledpin, output);
}

void loop()
{
  // here you'd put code needs running time.

  // check see if it's time blink led; is, if the
  // difference between current time , last time blinked
  // led bigger interval @ want to
  // blink led.
  unsigned long currentmillis = millis();
 
  if(currentmillis - previousmillis >= interval) {
    // save last time blinked led
    previousmillis = currentmillis;   

    // if led off turn on , vice-versa:
    if (ledstate == low)
      ledstate = high;
    else
      ledstate = low;

    // set led ledstate of variable:
    digitalwrite(ledpin, ledstate);
  }
}

i able manipulate blink without delay code bit use led on different pin , change constant long interval 1000 millis 250 millis


Arduino Forum > Using Arduino > Project Guidance > Snowball Throwing Target Project


arduino

Comments