// ~~~~~ This should be a comment ~~~~~ # this should be "include". This (should be) { a for loop } else { we're gettng rude }
Edited to add. That didn't seem to work right. Maybe I'll have to post some actual code?
DroneBot Workshop Robotics Engineer
James
#include Servo base, left, right, claw ; // creates 4 "servo objects" String str_Claw_Angle = ""; int int_Claw_Angle = 0; void setup() { Serial.begin(9600); base.attach(11); // attaches the servo on pin 11 to the base object left.attach(10); // attaches the servo on pin 10 to the left object right.attach(9); // attaches the servo on pin 9 to the right object claw.attach(5); // attaches the servo on pin 6 to the claw object base.write(90); // sets the servo position according to the value(degrees) left.write(90); // does the same right.write(90); // and again claw.write(25); // yes you've guessed it } void loop() { //Serial.println("Enter angle for claw:"); Serial.println("Enter Claw Angle:"); while (Serial.available() == 0) {} // wait for input str_Claw_Angle = Serial.readString(); int_Claw_Angle = str_Claw_Angle.toInt(); // say what you got: Serial.print("I received: "); Serial.println(int_Claw_Angle, DEC); if (int_Claw_Angle < 0 || int_Claw_Angle > 180) { Serial.println("Error in angle ,.. Try again."); } else { Serial.println("Setting Claw to angle"); claw.write(int_Claw_Angle); } }
Hmm? That didn't work either. I wonder what I'm doing wrong?
DroneBot Workshop Robotics Engineer
James
#include Servo base, left, right, claw ; // creates 4 "servo objects" String str_Claw_Angle = ""; int int_Claw_Angle = 0; void setup() { Serial.begin(9600); base.attach(11); // attaches the servo on pin 11 to the base object left.attach(10); // attaches the servo on pin 10 to the left object right.attach(9); // attaches the servo on pin 9 to the right object claw.attach(5); // attaches the servo on pin 6 to the claw object base.write(90); // sets the servo position according to the value(degrees) left.write(90); // does the same right.write(90); // and again claw.write(25); // yes you've guessed it } void loop() { //Serial.println("Enter angle for claw:"); Serial.println("Enter Claw Angle:"); while (Serial.available() == 0) {} // wait for input str_Claw_Angle = Serial.readString(); int_Claw_Angle = str_Claw_Angle.toInt(); // say what you got: Serial.print("I received: "); Serial.println(int_Claw_Angle, DEC); if (int_Claw_Angle < 0 || int_Claw_Angle > 180) { Serial.println("Error in angle ,.. Try again."); } else { Serial.println("Setting Claw to angle"); claw.write(int_Claw_Angle); } }
Still no workie pooh.
DroneBot Workshop Robotics Engineer
James
#include <Servo.h>
Servo base, left, right, claw ; // creates 4 "servo objects"
String str_Claw_Angle = "";
int int_Claw_Angle = 0;
void setup()
{
Serial.begin(9600);
base.attach(11); // attaches the servo on pin 11 to the base object
left.attach(10); // attaches the servo on pin 10 to the left object
right.attach(9); // attaches the servo on pin 9 to the right object
claw.attach(5); // attaches the servo on pin 6 to the claw object
base.write(90); // sets the servo position according to the value(degrees)
left.write(90); // does the same
right.write(90); // and again
claw.write(25); // yes you've guessed it
}
void loop()
{
//Serial.println("Enter angle for claw:");
Serial.println("Enter Claw Angle:");
while (Serial.available() == 0)
{} // wait for input
str_Claw_Angle = Serial.readString();
int_Claw_Angle = str_Claw_Angle.toInt();
// say what you got:
Serial.print("I received: ");
Serial.println(int_Claw_Angle, DEC);
if (int_Claw_Angle < 0 || int_Claw_Angle > 180)
{
Serial.println("Error in angle ,.. Try again.");
}
else
{
Serial.println("Setting Claw to angle");
claw.write(int_Claw_Angle);
}
}
~~~~~~~~~ If I paste the code in as just plain text it looks like above. But no indentations are preserved.
DroneBot Workshop Robotics Engineer
James
If you want to show code it is useful to use 'code' editing mode by clicking on the <> icon in the editor bar. The normal editor mode tries to do a bunch of editing behind the scene to make normal text look good such as striping leading tabs. Code mode allow you to cut and paste the raw code without additional editing.
I tried the Code icon, its a bit confusing. But here is one way to add code:
1 - Write your whole message out first, without the code. Then go to the part of your post that you want code inserted.
2 - Click the "Code" icon, which is the <> icon. You will see "PRE" written on the bottom of the editor.
3 - Now click on the "Source Code" icon, which is the {;} icon. A dialog box will pop up. It will have ALL the code from your post
4 - The dialog box has some tag in it that say "pre". Insert your code BETWEEN the tags.
5 - The code is now entered.
Here is an example:
void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
This is a bit awkward but it works!
"Never trust a computer you can’t throw out a window." — Steve Wozniak
text,...
#include Servo base, left, right, claw ; // creates 4 "servo objects" String str_Claw_Angle = ""; int int_Claw_Angle = 0; void setup() { Serial.begin(9600); base.attach(11); // attaches the servo on pin 11 to the base object left.attach(10); // attaches the servo on pin 10 to the left object right.attach(9); // attaches the servo on pin 9 to the right object claw.attach(5); // attaches the servo on pin 6 to the claw object base.write(90); // sets the servo position according to the value(degrees) left.write(90); // does the same right.write(90); // and again claw.write(25); // yes you've guessed it } void loop() { //Serial.println("Enter angle for claw:"); Serial.println("Enter Claw Angle:"); while (Serial.available() == 0) {} // wait for input str_Claw_Angle = Serial.readString(); int_Claw_Angle = str_Claw_Angle.toInt(); // say what you got: Serial.print("I received: "); Serial.println(int_Claw_Angle, DEC); if (int_Claw_Angle < 0 || int_Claw_Angle > 180) { Serial.println("Error in angle ,.. Try again."); } else { Serial.println("Setting Claw to angle"); claw.write(int_Claw_Angle); } }
more text,...
Edited to add: Ok, I think I got it now. ?
It would be nice to have preview button in the text editor so I can see how it will post before posting it. It's strange this forum didn't come with a preview button as a standard feature. It's a nice forum package overall though.
DroneBot Workshop Robotics Engineer
James
I just left a blank line for my code in the message and then inserted the code with paste, highlighted the code part and clicked <> above the editor field.
Works a treat!
DroneBot Workshop Robotics Engineer
James
DroneBot Workshop Robotics Engineer
James
testing code posting
[code]
int RPMinterval = 500;
long previousMillis = 0;
long currentMillis = 0;
float rpmR = 0;
float rpmL = 0;
[/code]
int RPMinterval = 500;
long previousMillis = 0;
long currentMillis = 0;
float rpmR = 0;
float rpmL = 0;
#include <Adafruit_SSD1306.h> //#include <NewPing.h> #include <MD_DS1307.h> #include <Adafruit_GFX.h> #include <TFT_HX8357.h> // Hardware-specific library TFT_HX8357 tft = TFT_HX8357(); // Invoke custom library #define TFT_GREY 0x5AEB // New colour //#include <TimerOne.h> #include <Wire.h> #include <Servo.h> #include <Adafruit_Sensor.h> #include <Adafruit_LSM303_U.h> Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(12345); #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 32 // OLED display height, in pixels
Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(12345); #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 32 // OLED display height, in pixel
int Dheading = 108; int heading ; int justshyofheading; int justoverheading;