Setup not working-Arduino

Thread Starter

Man10

Joined Jul 31, 2018
163
I connected a bts7960 board to a mabuchi 555 motor and I connected the bts7960 board to a 8 volt battery. I connected the bts7960 board to an arduino uno. The arduino uno is suppose to pick a random number. There are only 3 possibilities. They are 0, 1 and 2. If it picks a 1, it lowers a rock and then raises a rock. If it picks a 0 or 2, then it's not suppose to do anything. However sometimes it picks a 2 and lowers the rock and will not raise a rock.
This does not happen every single time. Sometimes it picks a 0 and lowers the rock and will not raise the rock. This does not happen every single time. Why is it not working as intended? If it were then if it picks a 0 or 2, then nothing would happen. But it sometimes lowers the rock, when picking a 0 or 2.
 

Thread Starter

Man10

Joined Jul 31, 2018
163
C:
long v;
Void setup() {
pinMode( 6, OUTPUT );
pinMode( 5, OUTPUT );

randomSeed( analogRead(0));
Serial.begin(9600);
v = random(0, 3);
Serial.println( v );

If( v == 1 ) {

analogWrite( 6, 100 );
anologWrite( 5, 0 );
delay(300);
analogWrite( 6, 0 );
anologWrite( 5, 0 );
delay(4000);
analogWrite( 6, 0 );
anologWrite( 5, 100 );
delay(300);
analogWrite( 6, 0 );
anologWrite( 5, 0 );
delay(4000);
}


}
Mod edit: code tags-JohnInTX
 
Last edited by a moderator:

Ya’akov

Joined Jan 27, 2019
9,069
setup() runs once, to set up various hardware and constants.

loop() runs after that, and loops until it is terminated.

If you want something to run over and over, put it in loop().
 

Thread Starter

Man10

Joined Jul 31, 2018
163
setup() runs once, to set up various hardware and constants.

loop() runs after that, and loops until it is terminated.

If you want something to run over and over, put it in loop().
I don't want it to run over and over. I want it to run only once when I start the program.
 

Thread Starter

Man10

Joined Jul 31, 2018
163
long v;
Void setup() {
pinMode( 6, OUTPUT );
pinMode( 5, OUTPUT );

randomSeed( analogRead(0));
Serial.begin(9600);
v = random(0, 3);
Serial.println( v );

If( v == 1 ) {

analogWrite( 6, 100 );
analogWrite( 5, 0 );
delay(300);
analogWrite( 6, 0 );
analogWrite( 5, 0 );
delay(4000);
analogWrite( 6, 0 );
analogWrite( 5, 100 );
delay(300);
analogWrite( 6, 0 );
analogWrite( 5, 0 );
delay(4000);
}


}
 

Thread Starter

Man10

Joined Jul 31, 2018
163
This is the code I wrote in the arduino ide. When I tried to copy the code I used onto the forum I made some typos.
 

trebla

Joined Jun 29, 2019
542
The code should work, unless Serial.println() does not interfere with PWM setup. You can insert a second long delay after print command to be sure. But i suspect loose wires, maybe from pin 6 or supply.
 
Top