Show Posts
Pages: 1 [2] 3 4 ... 23
16  Using Arduino / Programming Questions / Re: Sending 16 bits data from Arduino UNO on: February 03, 2014, 08:02:57 am
send them to be received by android phone or wireless.

Thanks !
17  Using Arduino / Programming Questions / Sending 16 bits data from Arduino UNO on: February 03, 2014, 07:47:26 am
Dear friend,

I was wondering how able to send 16 bits data from a 8 bit MCU ?

I got the idea on sending them seperately but how could I do that ?

Any advice ?

Thanks !
18  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 10, 2013, 07:33:39 am
Yes, quite possible.

How could that be ? Any hint ?

Thanks !
19  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 10, 2013, 07:29:07 am
I mean, based on the code, when it received the serial data of '5' , then it will execute the code when state ==5. This means it will continuously let the buzzer pin to be HIGH.

I would like to made so that when I first send the serial data '5', it will let buzzer pin HIGH. And when second time I send the '5' serial data, it will let the buzzer pin to be LOW.

Is that possible ?

Thanks !
20  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 10, 2013, 07:23:30 am
Quote
How could it possible for me to make that when I press a button the buzzer ON and when I press the same button again, it will OFF the buzzer ? Like toggling the pin.
There is an example, State Change Detection, that will show you how.
But I am using serial. when '5' is received, it will always in the loop isnt ?

Thanks !
21  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 10, 2013, 07:16:33 am
Quote
Can you explain why you need an interrupt ?
Homework assignment, I'm guessing.
Code segment :
Code:
else if (state == '5') {
   
     buzzerstatus =! buzzerstatus;

    digitalWrite(buzzer,buzzerstatus);
   
    if(flag == 0){
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Current State:");
      lcd.setCursor(0, 1);
      lcd.print("Buzzer ON");
      flag=1;
    }
     }

I am sending byte character from bluetooth device to my arduino. How could it possible for me to make that when I press a button the buzzer ON and when I press the same button again, it will OFF the buzzer ? Like toggling the pin.

Any idea ?

Thanks ! smiley
22  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 03, 2013, 11:57:48 am
Maybe just make an LED to blink  ?

Thanks
23  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 03, 2013, 11:26:54 am
Well, not consider as homework assignment. Just I would like to add one extra feature on my car.

Thanks!
24  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 03, 2013, 11:03:07 am
Quote
Okay, so if I put state = '0' , then it will execute the code for state == '0' ?
Unless there is more serial input that redefines state, and if you write some code for state == '0', yes.


Hey there, want to ask :

How do I add in simple interrupt function for my program ? I need to have at least one interrupt function.

Thanks for suggestion smiley-grin
25  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 03, 2013, 06:56:30 am
Thanks for the guidance !

I think I am on the correct way now !
26  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 03, 2013, 05:36:43 am
Okay, so if I put state = '0' , then it will execute the code for state == '0' ?

Correct me if I am wrong.

Thanks !
27  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 03, 2013, 05:29:13 am
I am using 0 instead of O.

When the mobile phone sent data '1' , so serial.read() will read it as 1 and assigned this 1 to the state. So the function with state == '1' will be executed. And at the end of the function when state == '1' , I assign state = 0. So does this means that the code under state == '1' will be executed once and it will return back to the function when state == ' 0 '?

Correct me if I am wrong.

Thanks !
28  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 03, 2013, 05:10:51 am
Quote
But supposedly when the state = 0 at the end of the code snippet 1, then it will run the section of the code when state == '1'?
I don't know because you only posted a snippet

Debug prints are just prints scattered around your code to give you some idea of what your code is actually doing.

This is my current coding :
Code:
int motorPin1 = 7;
int motorPin2 = 8;
int enablePin_1 = 6;
int motorPin4 = 2;
int motorPin3 = 4;
int enablePin_2 =3 ;
int buzzer = 11;
int f_b_light = 12 ;
int state;
int flag=0; //makes sure that the serial only prints once the state
boolean buzzerstatus = 0;
boolean LEDstatus = 0;

#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 10, 9, A0, A1, A2);

void setup() {
  // sets the pins as outputs:
  lcd.begin(16, 2);
  pinMode(buzzer,OUTPUT);
  pinMode(f_b_light,OUTPUT);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(enablePin_1, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(enablePin_2, OUTPUT);
  // sets enablePin high so that motor can turn on:
  digitalWrite(enablePin_1, HIGH);
  digitalWrite(enablePin_2, HIGH);
  pinMode(13,OUTPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop() {
  //if some date is sent, reads it and saves in state
  if(Serial.available() > 0){
    state = Serial.read();
    flag=0;
  }
  // if the state is '0' the DC motor will turn off
  if (state == '0') {
    digitalWrite(f_b_light,LOW);
    digitalWrite(buzzer,LOW);
    digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
    digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
    digitalWrite(motorPin3, LOW); // set pin 2 on L293D low
    digitalWrite(motorPin4, LOW); // set pin 7 on L293D low
    if(flag == 0){
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Current State:");
      lcd.setCursor(0, 1);
      lcd.print("STOP");
      flag=1;
      state=0;
    }
  }
  // if the state is '1' the motor will forward
  else if (state == '1') {
    digitalWrite(f_b_light,LOW);
    digitalWrite(buzzer,LOW);
    digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
    digitalWrite(motorPin2, HIGH); // set pin 7 on L293D high
    digitalWrite(motorPin3, LOW); // set pin 2 on L293D low
    digitalWrite(motorPin4, HIGH); // set pin 7 on L293D high
    delay(100);
   
    if(flag == 0){
      lcd.setCursor(0, 0);
      lcd.print("Current State:");
      lcd.setCursor(0, 1);
      lcd.print("FORWARD");
      flag=1;
       state=0;
    }
  }
  // if the state is '2' the motor will backward
  else if (state == '2') {
    digitalWrite(f_b_light,LOW);
    digitalWrite(buzzer,LOW);
    digitalWrite(motorPin1, HIGH); // set pin 2 on L293D high
    digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
    digitalWrite(motorPin3, HIGH); // set pin 2 on L293D high
    digitalWrite(motorPin4, LOW); // set pin 7 on L293D low
    delay(100);
     
    if(flag == 0){
      lcd.setCursor(0, 0);
      lcd.print("Current State:");
      lcd.setCursor(0, 1);
      lcd.print("REVERSE");
      flag=1;
       state=0;
    }
  }

  else if (state == '3') {
    digitalWrite(f_b_light,LOW);
    digitalWrite(buzzer,LOW);
    digitalWrite(motorPin1, LOW); // set pin 2 on L293D high
    digitalWrite(motorPin2, HIGH); // set pin 7 on L293D low
    digitalWrite(motorPin3, LOW); // set pin 2 on L293D high
    digitalWrite(motorPin4, LOW); // set pin 7 on L293D low
    delay(150);
      digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
    digitalWrite(motorPin2, LOW); // set pin 7 on L293D high
    digitalWrite(motorPin3, LOW); // set pin 2 on L293D low
    digitalWrite(motorPin4, LOW); // set pin 7 on L293D high
    if(flag == 0){
      lcd.setCursor(0, 0);
      lcd.print("Current State:");
      lcd.setCursor(0, 1);
      lcd.print("RIGHT");
      flag=1; //Left wheel forward, Right wheel static
      flag=1;
       state='1';
    }
  }
  else if (state == '4') {
    digitalWrite(f_b_light,LOW);
    digitalWrite(buzzer,LOW);
    digitalWrite(motorPin1, LOW); // set pin 2 on L293D high
    digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
    digitalWrite(motorPin3, LOW); // set pin 2 on L293D high
    digitalWrite(motorPin4, HIGH); // set pin 7 on L293D low
    delay(150);
     digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
    digitalWrite(motorPin2, LOW); // set pin 7 on L293D high
    digitalWrite(motorPin3, LOW); // set pin 2 on L293D low
    digitalWrite(motorPin4, LOW); // set pin 7 on L293D high
    if(flag == 0){
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Current State:");
      lcd.setCursor(0, 1);
      lcd.print("LEFT");
      flag=1;
       state='1';
    }
  }
  else if (state == '5') {

    digitalWrite(buzzer,HIGH);
    delay(100);
    digitalWrite(buzzer,LOW);
    if(flag == 0){
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Current State:");
      lcd.setCursor(0, 1);
      lcd.print("Buzzer ON");
      flag=1;
       state=0;
    }
  }
  else if (state == '6') {

    digitalWrite(f_b_light,HIGH);
    delay(100);
     digitalWrite(f_b_light,LOW);
    if(flag == 0){
      lcd.setCursor(0, 0);
      lcd.print("Current State:");
      lcd.setCursor(0, 1);
      lcd.print("LIGHT ON");
      flag=1;
       state = 0;
    }
  }

}
When state == '6' , then it will cause the f_b_light to be HIGH, and at the end of this function, state = 0. Does this means that the code will execute once and it jumps back to the function when state =='0' ?

Thanks !
29  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 03, 2013, 04:58:56 am
Quote
Correct me if I am wrong.
What do your debug statements tell you?

Oh? Why don't you have any?
What do you mean by that ?

Thanks !
30  Using Arduino / Programming Questions / Re: 2WD Electric Car on: December 03, 2013, 04:56:31 am
There's nothing in the first snippet to turn the LED off.
But supposedly when the state = 0 at the end of the code snippet 1, then it will run the section of the code when state == '1'?

Correct me if I am wrong.

Thanks !
Pages: 1 [2] 3 4 ... 23