Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 23
61  Using Arduino / Project Guidance / Re: Mini Piano V1.0 on: August 30, 2013, 10:29:05 am
Code:
int led = A0;
int speaker = 13;
int button_1 = 0;
int button_2 = 1;
int button_3=2;
int button_4 = 3;
int button_5 = 4;
int button_6=5;
int button_7=6;
int button_8=7;
int button_9=8;
int button_10=9;
int button_11=10;
int button_12=11;
int button_13=12;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
 
  pinMode(speaker,OUTPUT);
pinMode(0,INPUT);
pinMode(1,INPUT);
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(5,INPUT);
pinMode(6,INPUT);
pinMode(7,INPUT);
pinMode(8,INPUT);
pinMode(9,INPUT);
pinMode(10,INPUT);
pinMode(11,INPUT);
pinMode(12,INPUT);
pinMode(A0,OUTPUT);
digitalWrite(0,HIGH);
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
noTone(13);
}

// the loop routine runs over and over again forever:
void loop() {
  if(digitalRead(0) == LOW)
  {
     digitalWrite(led, HIGH);
    tone(13,262);
     }
    else  if(digitalRead(1) == LOW)
     {digitalWrite(led, HIGH);
       tone(13,294);
     }
      else  if(digitalRead(2) == LOW)
     {
       digitalWrite(led, HIGH);
       tone(13,330);
     }
      else  if(digitalRead(3) == LOW)
     {
       digitalWrite(led, HIGH);
       tone(13,349);
     }
      else  if(digitalRead(4) == LOW)
     {
       digitalWrite(led, HIGH);
       tone(13,392);
     }
     else  if(digitalRead(5) == LOW)
     {
       digitalWrite(led, HIGH);
       tone(13,440);
     }
     else  if(digitalRead(6) == LOW)
     {
       digitalWrite(led, HIGH);
       tone(13,494);
     }
      else  if(digitalRead(7) == LOW)
     {
       digitalWrite(led, HIGH);
       tone(13,523);
     }
     else  if(digitalRead(8) == LOW)
     {
       digitalWrite(led, HIGH);
       tone(13,277);
     }
      else  if(digitalRead(9) == LOW)
     {
       digitalWrite(led, HIGH);
       tone(13,311);
     }
     else  if(digitalRead(10) == LOW)
     {
       digitalWrite(led, HIGH);
       tone(13,370);
     }
      else  if(digitalRead(11) == LOW)
     {
       digitalWrite(led, HIGH);
       tone(13,415);
     }
      else  if(digitalRead(12) == LOW)
     {
       digitalWrite(led, HIGH);
       tone(13,466);
     }
     else
     {
       digitalWrite(led, LOW);
       noTone(13);
     }
 
     
}

This is my code.

Thank you
62  Using Arduino / Project Guidance / Re: Mini Piano V1.0 on: August 30, 2013, 09:58:31 am
The binary sketch size for that code is just 3196 bytes smiley
63  Using Arduino / Project Guidance / Re: Mini Piano V1.0 on: August 30, 2013, 09:35:11 am
Do not play the tone. All they key are same tone. Same frequency instead
64  Using Arduino / Project Guidance / Mini Piano V1.0 on: August 30, 2013, 09:23:05 am
https://gist.github.com/vick5821/6390286
I made the mini piano using this coding. When I use atmegha 328 it works perfectly. However, when I upload the code through USB or USBasp to the atmega 8, it does not work as expected.

What is the problem actually ? Suppose any kind of cheap should work ?

Thanks !
65  Using Arduino / Programming Questions / Re: Car chasis with HC-SR04 sensor on: August 05, 2013, 01:33:40 pm
Ok, thanks for pointing out my mistakes.

Will do better smiley
66  Using Arduino / Project Guidance / Re: Documentation Coding on: August 05, 2013, 01:38:44 am
Thank you so much !

Appreciate your kind help smiley
67  Using Arduino / Project Guidance / Re: Documentation Coding on: August 05, 2013, 01:28:24 am
Do you have the list of colours ? That would be perfect.

Thanks and appreciate smiley
68  Using Arduino / Project Guidance / Re: Documentation Coding on: August 05, 2013, 01:24:12 am
Yes, I am changing. Will update soon !

Thanks alot !
69  Using Arduino / Project Guidance / Re: Documentation Coding on: August 05, 2013, 01:20:13 am
But I think can change the colour scheme right ? Just I am not sure what is the colour scheme for instructions and so....

Thank you
70  Using Arduino / Project Guidance / Re: Documentation Coding on: August 05, 2013, 01:10:22 am
Okay, the steps work well !

This is what I get as attached. But somehow a little bit different colour and format when like open up in arduino IDE

Any ideas ?

Thank you

71  Using Arduino / Project Guidance / Re: Documentation Coding on: August 05, 2013, 12:58:50 am
Do I need to do the steps everytime when I wanted to copy a new code to MS Word ?

Thank you
72  Using Arduino / Project Guidance / Documentation Coding on: August 04, 2013, 10:32:31 pm
Dear all, what software can I use to get my code neatly display in my documentation for arduino code in mirosoft word ?

See the attachment for more details.

Thank you.
73  Using Arduino / Programming Questions / Re: Car chasis with HC-SR04 sensor on: August 04, 2013, 10:59:09 am
I actually just copy the code from arduino IDE and I select copy to forum then I paste everything here. Did I do mistakes ?

Thanks for pointing out to me if any smiley
74  Using Arduino / Programming Questions / Re: Car chasis with HC-SR04 sensor on: August 04, 2013, 10:54:08 am
Already modified smiley
75  Using Arduino / Programming Questions / Re: Car chasis with HC-SR04 sensor on: August 04, 2013, 10:45:45 am
Quote
int motorPin1 = 7;
int motorPin2 = 8;
int enablePin_1 = 6;
int motorPin4 = 2;
int motorPin3 = 4;
int enablePin_2 =3 ;
int state;
int flag=0; //makes sure that the serial only prints once the state
 
void setup() {
// sets the pins as outputs:
  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(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){
                Serial.println("Motor: off");
                flag=1;
                }
          }
// if the state is '1' the motor will turn right
         else if (state == '1') {
            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
              if(flag == 0){
                Serial.println("Motor: Forward");
                flag=1;
                  }
          }
// if the state is '2' the motor will turn left
          else if (state == '2') {
            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
              if(flag == 0){
                Serial.println("Motor: Reverse");
                flag=1;
                  }
          }
          else if (state == '3') {
            digitalWrite(motorPin1, HIGH); // 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
              if(flag == 0){
                 Serial.println("Motor: Left_1");//180 degree rotate
                flag=1;
                  }
          }
          else if (state == '4') {
            digitalWrite(motorPin1, LOW); // set pin 2 on L293D high
            digitalWrite(motorPin2, HIGH); // set pin 7 on L293D low
            digitalWrite(motorPin3, HIGH); // set pin 2 on L293D high
            digitalWrite(motorPin4, LOW); // set pin 7 on L293D low
              if(flag == 0){
                Serial.println("Motor: Right_1");//180 degree rotate
                flag=1;
                  }
          }
          else if (state == '5') {
            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
              if(flag == 0){
                Serial.println("Motor: Right_2 "); //Left wheel forward, Right wheel static
                flag=1;
                  }
          }
           else if (state == '6') {
             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
                if(flag == 0){
                  Serial.println("Motor: Left_2"); //Right wheel forward, left wheel static
                  flag=1;
                    }
          }

}


Modified !

Thank you smiley
Pages: 1 ... 3 4 [5] 6 7 ... 23