Need help with code for solenoid project.

Hello there!
This is my first post.
I've been working with a family member on a small project, we needed to set the speed at which a solenoid works, and we found out that the arduino and do such a function.
What I need is someone to help me with the code.

We built this, but have nooo clue as to what the code should be.
We found this on a different website for a different setup.
http://learn.robotgeek.com/demo-code/124-arduino-solenoid-tutorial-button-demo.html

What do we change here, or, what should the code look like in order to recreate what the first video showed.

/*

Controlling a Solenoid with Arduino

This demo shows how to control a solenoid using pushbuttons and a relay with
your Arduino compatable controller.
 - The first button will hold the solenoid/relay on while it is held
 - The second button will hold the solenoid/relay on for 2 seconds
 
 
 The circuit:
 * RobotGeek Pushbutton - Digital Pin 2
 * RobotGeek Pushbutton - Digital Pin 4
 * RobotGeek Relay - Digital Pin 7
 
Products Used in this demo:
 - http://www.robotgeek.com/solenoids
 - http://www.robotgeek.com/robotgeek-geekduino-sensor-kit
 - http://www.robotgeek.com/robotGeek-pushbutton
 - http://www.robotgeek.com/robotgeek-relay

 */

// constants won't change. They're used here to set pin numbers:
const int button1Pin = 2;     // the number of the pushbutton1 pin
const int button2Pin = 4;     // the number of the pushbutton2 pin
const int relayPin =  7;      // the number of the Relay pin

// variables will change:
int button1State = 0;         // variable for reading the pushbutton status
int button2State = 0;         // variable for reading the pushbutton status

void setup() { 
  
  // initialize the pushbutton pin as an input:
  pinMode(button1Pin, INPUT);     
  pinMode(button2Pin, INPUT);    
  // initialize the relay pin as an output:
  pinMode(relayPin, OUTPUT);    
   
}

void loop(){
  
  // read the state of the pushbutton values:
  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);

  // check if the pushbutton1 is pressed.
  // if it is we turn on the relay/solenoid
  if (button1State == HIGH) {     
    // turn relay on:    
    digitalWrite(relayPin, HIGH);  
  } 
  // When we let go of the button, turn off the relay
  else if ((button1State == LOW) && (digitalRead(relayPin) == HIGH)) {
    // turn relay off
    digitalWrite(relayPin, LOW); 
  }  
  
  
  // For the second button, we just activate the solenoid/relay for two seconds
  if (button2State == HIGH) {     
    // turn relay on   
    digitalWrite(relayPin, HIGH); 
    delay(2000);    // waits for 2 seconds
    //turn relay off
    digitalWrite(relayPin, LOW); 
  } 

}

Any help is greatly appreciated. I'm a newbie to this stuff myself, and i've been doing different code tutorials, I simply don't know what to do just yet.

Do you want the solenoid to cycle on and off continuously (like it is in the video), or do you want to control it using a push button (as the code you posted does)?

If you have the hardware working, that's the hard part....

Take a look at the [u]Blink LED Example[/u]. The delay time is in milliseconds and you can change the on & times independently, or you can make it a variable that changes every time through the loop.

Note that the delay() function is rarely used in "real" programs because the program is can't do anything else (such as respond to a button push) during the delay-time.

If you are going to be doing anything else with the Arduino, I recommend you read-through the [u]Language Reference[/u]. You won't understand it all, and you won't remember it all, but it should give you a good idea of how the Arduino works. The most important concepts in programming are conditional branching (if-statements, etc) and loops (doing things over-and-over, usually until some condition is met). Once you understand those concepts, you'll start to understand how programming works.

BTW - If you simply want to cycle a solenoid or pulse an LED, a [u]555 chip[/u] is more economical and doesn't require any software.

DVDdoug:
If you have the hardware working, that's the hard part....

Take a look at the [u]Blink LED Example[/u]. The delay time is in milliseconds and you can change the on & times independently, or you can make it a variable that changes every time through the loop.

Note that the delay() function is rarely used in "real" programs because the program is can't do anything else (such as respond to a button push) during the delay-time.

If you are going to be doing anything else with the Arduino, I recommend you read-through the [u]Language Reference[/u]. You won't understand it all, and you won't remember it all, but it should give you a good idea of how the Arduino works. The most important concepts in programming are conditional branching (if-statements, etc) and loops (doing things over-and-over, usually until some condition is met). Once you understand those concepts, you'll start to understand how programming works.

BTW - If you simply want to cycle a solenoid or pulse an LED, a [u]555 chip[/u] is more economical and doesn't require any software.

Never heard of a 555 chip, I think that would be better. I'll look up tutorials, looks interesting, thank you!