Project 3

 

Solo-Universe with Navigation system prototype

IMG_2624 IMG_2625

 

 

IMG_2627

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Code:

SEND:

const int buttonPin = 9; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

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

void setup() {
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
Serial.println(buttonState, DEC);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
Serial.println(buttonState, DEC);
digitalWrite(ledPin, LOW);
}
}

RECEIVE:

int pot = 0;
//int relay = 3;
int motorPin = 9;
int message = 0;

void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
pinMode(pot, INPUT);
// pinMode(relay, OUTPUT);
pinMode(motorPin, OUTPUT);
}

int getPot() {
int v;
v = analogRead(pot);
v /= 4;
v = max(v, 30);
v = min(v, 255);
return v;
}

int motorFoward() {
analogWrite(motorPin, getPot());
delay(1000);
digitalWrite(motorPin, LOW);
delay(1000);
digitalWrite(motorPin, HIGH);
// Serial.println(getIR());
delay(1000);
}

int motorBackward() {
analogWrite(motorPin, getPot());
delay(1000);
digitalWrite(motorPin, LOW);
delay(1000);
//digitalWrite(motorPin, LOW);
//Serial.println(getIR());
//delay(1000);
}

void loop() // run over and over again
{
if( message == 1){
motorFoward();
motorBackward();
}
else {
digitalWrite(motorPin,LOW);
}}

void serialEvent(){
while(Serial.available()){
message = Serial.read();
}
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

code:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: