Skip to content

Commit a82d819

Browse files
Add files via upload
Stab. has been finished.
1 parent b66e7d2 commit a82d819

File tree

1 file changed

+61
-30
lines changed

1 file changed

+61
-30
lines changed

Main.ino

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ DIR_A = 12,
2929
BRAKE_A = 9,
3030
SNS_A = A0;
3131

32+
const int
33+
PWM_B = 11,
34+
DIR_B = 13,
35+
BRAKE_B = 8,
36+
SNS_B = A1;
37+
3238
int sensorPin1 = A1; // select the input pin for the gyrometer // gyrometer wiper (middle terminal) connected to analog pin 1
3339
// outside leads to ground and +3.3V
3440
int sensorValue1 = 0; // variable to store the value coming from the sensor
@@ -211,6 +217,10 @@ void setup() {
211217
pinMode(BRAKE_A, OUTPUT); // Brake pin on channel A
212218
pinMode(DIR_A, OUTPUT); // Direction pin on channel A
213219

220+
// Configure the B output
221+
pinMode(BRAKE_B, OUTPUT); // Brake pin on channel B
222+
pinMode(DIR_B, OUTPUT); // Direction pin on channel B
223+
214224
// Open Serial communication
215225
Serial.begin(9600); // set up Serial library at 9600 bps
216226
Serial.println("Motor shield DC motor Test:\n");
@@ -332,14 +342,14 @@ void loop() {
332342
// while(1);
333343

334344
// read the value from the gyrometer sensor:
335-
sensorValue1 = analogRead(sensorPin1); // - 512;
336-
Serial.println("From the gyrometer : ");
337-
Serial.print(sensorValue1, DEC);
338-
Serial.println("");
345+
// sensorValue1 = analogRead(sensorPin1); // - 512;
346+
// Serial.println("From the gyrometer : ");
347+
// Serial.print(sensorValue1, DEC);
348+
// Serial.println("");
339349
// scanner.Scan();
340350

341351
// a little delay to not hog Serial Monitor
342-
delay(100);
352+
// delay(100);
343353

344354
// change the resolution to 12 bits and read A1
345355
// analogReadResolution(12);
@@ -354,6 +364,7 @@ void loop() {
354364
bno.getEvent(&event);
355365

356366
/* Display the floating point data */
367+
357368
Serial.print("X: ");
358369
Serial.print(event.orientation.x, 4);
359370
Serial.print("\tY: ");
@@ -396,10 +407,10 @@ void loop() {
396407
//uint8_t i;
397408

398409
// read the value from the gyrometer sensor:
399-
sensorValue1 = analogRead(sensorPin1); // - 512;
400-
Serial.println("From the gyrometer : ");
401-
Serial.print(sensorValue1, DEC);
402-
Serial.println("");
410+
// sensorValue1 = analogRead(sensorPin1); // - 512;
411+
// Serial.println("From the gyrometer : ");
412+
// Serial.print(sensorValue1, DEC);
413+
// Serial.println("");
403414
/*
404415
// read the value from the inclinometer sensor:
405416
sensorValue2 = analogRead(sensorPin2);
@@ -473,16 +484,17 @@ void loop() {
473484
// turn on motor
474485
// myMotor->run(RELEASE);
475486

476-
#ifdef TRUE
477487
// here the stab. has been done with the inclinometer
488+
// Serial.print("\n\tY: ");
489+
// Serial.print(event.orientation.y, 4);
478490
if (event.orientation.y > 0)
479491
{
480492
// myMotor->run(BACKWARD);
481493
Serial.println("Backward");
482494
digitalWrite(BRAKE_A, LOW); // setting againg the brake LOW to disable motor brake
483495
digitalWrite(DIR_A, LOW); // now change the direction to backward setting LOW the DIR_A pin
484496
// myMotor->setSpeed(event.orientation.y *2);
485-
analogWrite(PWM_A, event.orientation.y *2);
497+
analogWrite(PWM_A, event.orientation.y *10);
486498
// myNextMotor->step(4, FORWARD, MICROSTEP);
487499
}
488500
else
@@ -492,10 +504,31 @@ void loop() {
492504
digitalWrite(BRAKE_A, LOW); // setting brake LOW disable motor brake
493505
digitalWrite(DIR_A, HIGH); // setting direction to HIGH the motor will spin forward
494506
// myMotor->setSpeed(-1 *event.orientation.y *2);
495-
analogWrite(PWM_A, -1 *event.orientation.y *2);
507+
analogWrite(PWM_A, -1 *event.orientation.y *10);
496508
// myNextMotor->step(4, BACKWARD, MICROSTEP);
497509
}
498510

511+
if (event.orientation.z > 0)
512+
{
513+
// myMotor->run(BACKWARD);
514+
Serial.println("Backward");
515+
digitalWrite(BRAKE_B, LOW); // setting againg the brake LOW to disable motor brake
516+
digitalWrite(DIR_B, LOW); // now change the direction to backward setting LOW the DIR_A pin
517+
// myMotor->setSpeed(event.orientation.z *2);
518+
analogWrite(PWM_B, event.orientation.z *10);
519+
// myNextMotor->step(4, FORWARD, MICROSTEP);
520+
}
521+
else
522+
{
523+
// myMotor->run(FORWARD);
524+
Serial.println("forward");
525+
digitalWrite(BRAKE_B, LOW); // setting brake LOW disable motor brake
526+
digitalWrite(DIR_B, HIGH); // setting direction to HIGH the motor will spin forward
527+
// myMotor->setSpeed(-1 *event.orientation.z *2);
528+
analogWrite(PWM_B, -1 *event.orientation.z *10);
529+
// myNextMotor->step(4, BACKWARD, MICROSTEP);
530+
}
531+
}
499532
// here the stab. has been done with the inclinometer
500533
// if (event.orientation.z > 0)
501534
// {
@@ -508,28 +541,27 @@ void loop() {
508541
// myOtherMotor->run(FORWARD);
509542
// myOtherMotor->setSpeed(-1 *event.orientation.z *2);
510543
// myNextMotor->step(4, BACKWARD, MICROSTEP);
511-
}
512-
#else
544+
// }
545+
513546
// here the stab. has been done with the gyrometer
514-
if (sensorValue1 > 0)
515-
{
547+
// if (sensorValue1 > 0)
548+
// {
516549
// myMotor->run(FORWARD);
517-
Serial.println("forward");
518-
digitalWrite(BRAKE_A, LOW); // setting brake LOW disable motor brake
519-
digitalWrite(DIR_A, HIGH); // setting direction to HIGH the motor will spin forward
550+
// Serial.println("forward");
551+
// digitalWrite(BRAKE_A, LOW); // setting brake LOW disable motor brake
552+
// digitalWrite(DIR_A, HIGH); // setting direction to HIGH the motor will spin forward
520553
// myMotor->setSpeed(sensorValue1);
521-
analogWrite(PWM_A, 255); //sensorValue1);
522-
}
523-
else
524-
{
554+
// analogWrite(PWM_A, 255); //sensorValue1);
555+
// }
556+
// else
557+
// {
525558
// myMotor->run(BACKWARD);
526-
Serial.println("Backward");
527-
digitalWrite(BRAKE_A, LOW); // setting againg the brake LOW to disable motor brake
528-
digitalWrite(DIR_A, LOW); // now change the direction to backward setting LOW the DIR_A pin
559+
// Serial.println("Backward");
560+
// digitalWrite(BRAKE_A, LOW); // setting againg the brake LOW to disable motor brake
561+
// digitalWrite(DIR_A, LOW); // now change the direction to backward setting LOW the DIR_A pin
529562
// myMotor->setSpeed(-1 *sensorValue1);
530-
analogWrite(PWM_A, 255); //-1 *sensorValue1);
531-
}
532-
#endif
563+
// analogWrite(PWM_A, 255); //-1 *sensorValue1);
564+
// }
533565
//#ifdef TRUE
534566
/*
535567
Serial.println("Single coil steps");
@@ -578,4 +610,3 @@ void loop() {
578610
delay(1000);
579611
//#endif
580612
*/
581-
}

0 commit comments

Comments
 (0)