Im working on code that will make blobs behaviour unpredictable. So that every time it gets bitten it reacts differently. The code isn't finished yet but anyway.
ARDUINO CODE
// set pin numbers:
const int buttonPin = 7; // the number of the reedswitch pin
long randNumber;
//const int motorPin = 8; // the number oh the motor pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;
int timer = 100;
void setup() {
// initialize the reedswitch pin as an input:
pinMode(buttonPin, INPUT);
// initialize the motor as as output
// pinMode(motorPin, OUTPUT);
// initialize the LED pin as an output:
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
pinMode(pin5, OUTPUT);
randomSeed(analogRead(0));
Serial.begin(9600);
}
void loop(){
// read the state of the reedswitch value:
buttonState = digitalRead(buttonPin);
// check if the reedswitch is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
randNumber = random(5);
delay(50);
Serial.println(randNumber); }
if ( randNumber==1){
digitalWrite(pin2,HIGH);
delay(1000);
digitalWrite(pin4,HIGH);
delay(1000);}
else if ( randNumber==4){
digitalWrite(pin2, HIGH);
delay(timer);
digitalWrite(pin2, LOW);
delay(timer);
digitalWrite(pin4, HIGH);
delay(timer);
digitalWrite(pin4, LOW);
delay(timer);
digitalWrite(pin3, HIGH);
delay(timer);
digitalWrite(pin3, LOW);
delay(timer);
digitalWrite(pin5, HIGH);
delay(timer);
digitalWrite(pin5, LOW);
delay(timer);
digitalWrite(pin5, HIGH);
delay(timer);
digitalWrite(pin5, LOW);
delay(timer);
digitalWrite(pin2, HIGH);
delay(timer);
digitalWrite(pin2, LOW);
delay(timer);
digitalWrite(pin4, HIGH);
delay(timer);
digitalWrite(pin4, LOW);
delay(timer);
digitalWrite(pin3, HIGH);
delay(timer);
digitalWrite(pin3, LOW);
delay(timer);
digitalWrite(pin5, HIGH);
delay(timer);
digitalWrite(pin5, LOW);
delay(timer);
digitalWrite(pin5, HIGH);
delay(timer);
digitalWrite(pin5, LOW);
delay(timer);
digitalWrite(pin3, HIGH);
delay(timer);
digitalWrite(pin3, LOW);
delay(timer);
digitalWrite(pin4, HIGH);
delay(timer);
digitalWrite(pin4, LOW);
delay(timer);}
else if ( randNumber==2){
// i=0;
// turn LED off:
digitalWrite(pin2, HIGH);
digitalWrite(pin4, HIGH);
digitalWrite(pin3, HIGH);
digitalWrite(pin5, HIGH);}
else {
// turn motor off:
//digitalWrite(motorPin, LOW);
// turn LED off:
digitalWrite(pin2, LOW);
digitalWrite(pin4, LOW);
digitalWrite(pin3, LOW);
digitalWrite(pin5, LOW);
}}
Tuesday, March 2, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment