Pages: [1]   Go Down
Author Topic: Need some help  (Read 386 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The situation:
In march I have to present a work for school.. it's named 'robotics for dummies'. Using the arduino I want to controll a RC-model car (the RC part replaced by the arduino and some other electronics). To keep it simple, I'm only using 3 microswitches (2 in front, and 1 in the back).

The problem:
I don't have the arduino YET! It will arrive in february. So I'm very short in time...
I've read a couple of tutorials and I'm already trying to make the program before I have the arduino.
But I might need some help since I can't test the program.

I'll translate a few comments from dutch to english. But if there is someone that speaks dutch, prepared to help me I would be verry happy!

The code:
Code:
/*
 *  RC-auto Versie 0.1
 *  Tokesnugerd - Eindwerk Salco Haasrode '07/'08
 *
 *  Dit programma moet de auto in staat stellen om door middel -> description what the program should do
 *  van 3 druksensoren rond te rijden zonder vast te steken. -> description what the program should do
 */
 
int Slv = #pin;        // Pin where the front left switch is connected to
int Srv = #pin;        // Pin where the front right switch is connected to
int Sa  = #pin;        // Pin where the rear switch is connected to

void setup() {
  Serial.begin(9600);   // Prepare serial
  pinMode(Slv, INPUT);  // Slv is input
  pinMode(Srv, INPUT);  // Srv is input
  pinMode(Sa, INPUT);   // Sa is input
  
  Serial.println("Ik start het programma!");  // Says that program is starting
}

void BOTSlv() {                                    
  Serial.println("Ik ben links vanvoor gebotst!"); // Send message that there has been a collision front left
}

void BOTSrv() {                                    
  Serial.println("Ik ben rechts vanvoor gebotst!"); // Send message that there has been a collision front right
}

void BOTSa() {                                        
  Serial.println("Ik ben rechts vanachter gebotst!"); // Send message that there has been a collision rear
}

void loop() {
  if (digitalRead(Slv) == LOW){  // front left collision
    BOTSlv();                    
  }
  if (digitalRead(Srv) == LOW){  // front right collision
    BOTSrv();                    
  }
  if (digitalRead(Sa) == LOW){  // rear collision
    BOTSa();                    
  }
}

That's all.. as you can see there isn't much about it.. but I want to be sure that the basics aren't full of errors!
May I post here another version when that one is completed ?

Thanks!!!!
Toke
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can install and run the Arduino IDE without a board to check the syntax of your
code.

The sketch you posted is a good start. You do have an error in the initialisation of  the variables defining the  pins,  (#pin needs to be replaced with a number representing the digital pin you want to read)

Good luck!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That was one I was aware of smiley Its done counsciously (written correctly ?? smiley) because I don't know the pins I will be using yet..
The next step is the motor movement..

The IDE doens't give any errors (when choosing a random number as a pin) so I think this should work ?

I suppose there isn't an emulator or something like that...


Thanks for your response !
Logged

Pages: [1]   Go Up
Jump to: