why wont this compole? - Page 1
Forum section: electronics / general

author: m3vuv
author_rank: Super Contributor
timestamp: November 03, 2019, 03:22:50 pm
content: Hi all,im trying to get this on to an arduino uno,it comes up with an error msg saying"expected unqualified-id before '(' token heres the sketch:/*http://www.bristolwatch.com/radio/arduino_coil_winder.htmArduino Stepper Motor Coil WinderLewis Loflinlewis@bvu.net*/#define yellow 9 //Q1#define orange 10 //Q2#define brown 11 // Q3#define black 12 // Q4#define SW0 2#define SW1 3#define SW2 4#define SW3 5#include <OneWire.h>#include <Wire.h>#include <LiquidCrystal_I2C.h>LiquidCrystal_I2C lcd(0x27, 16, 2);// set the LCD address to 0x27int i, j;void setup() {pinMode(SW0, INPUT);pinMode(SW1, INPUT);pinMode(SW2, INPUT);pinMode(SW3, INPUT);digitalWrite(SW0, 1); // pull up ondigitalWrite(SW1, 1); // pull up ondigitalWrite(SW2, 1);digitalWrite(SW3, 1);lcd.init(); // initialize the lcdlcd.backlight();pinMode(black, OUTPUT);pinMode(brown, OUTPUT);pinMode(orange, OUTPUT);pinMode(yellow, OUTPUT);all_coils_off();lcd.clear();lcd.home();lcd.print("Wait 2 sec.");delay(2000); // wait for 2 secondslcd.setCursor(0, 1); // is Homelcd.print("Ready to go!");j = 0;}void loop() {// set turnsif (!digitalRead(SW0) == 1) {delay(1000);j = 0;lcd.clear();lcd.home();lcd.print("Turns = 0 ");while (!digitalRead(SW0) == 1) {delay(1000);if (!digitalRead(SW1) == 1) j = j + 1;if (!digitalRead(SW2) == 1) j = j + 10;lcd.setCursor(8, 0);lcd.print(j);} // end whilelcd.setCursor(0, 1);lcd.print("Ready to wind.");}if (!digitalRead(SW3)) {lcd.clear();lcd.home();lcd.print("Turns 0 ");for (i = 1; i <= j; i++) {reverse(200);lcd.setCursor(6, 0);lcd.print(i);}all_coils_off();lcd.setCursor(0, 1);lcd.print("Finished ");}} // end loopvoid all_coils_off(void) {digitalWrite(black, 0);digitalWrite(brown, 0);digitalWrite(orange, 0);digitalWrite(yellow, 0);}void reverse(int i) {while (1) {digitalWrite(black, 1);digitalWrite(brown, 0);digitalWrite(orange, 0);digitalWrite(yellow, 1);delay(analogRead(0) / 4 + 5);i--;if (i < 1) break;digitalWrite(black, 0);digitalWrite(brown, 1);digitalWrite(orange, 0);digitalWrite(yellow, 1);delay(analogRead(0) / 4 + 5);i--;if (i < 1) break;digitalWrite(black, 0);digitalWrite(brown, 1);digitalWrite(orange, 1);digitalWrite(yellow, 0);delay(analogRead(0) / 4 + 5);i--;if (i < 1) break;digitalWrite(black, 1);digitalWrite(brown, 0);digitalWrite(orange, 1);digitalWrite(yellow, 0);delay(analogRead(0) / 4 + 5);i--;if (i < 1) break;}}any idear what im doing wrong?,cheers Paul.

author: sokoloff
author_rank: Super Contributor
timestamp: November 03, 2019, 03:31:40 pm
content: I just copied your code into my environment and it compiles fine as-is.Arduino 1.8.10 on MacOS.I had to install two libraries:OneWire - v2.3.5 by Jim Studt and a long list of other peopleLiquidCrystal_I2C - v1.1.12 by Frank de Brabander

author: donotdespisethesnake
author_rank: Super Contributor
timestamp: November 03, 2019, 03:34:34 pm
content: @sokoloff beat me to it, but compiles fine here on Arduino 1.8.3 with the additional libraries installed.

author: Andy Watson
author_rank: Super Contributor
timestamp: November 03, 2019, 04:24:57 pm
content: Did you copy and paste the code from a web-page? If so, and considering the above two replies, there might be a non-printing ascci character embeded in the code.

author: m3vuv
author_rank: Super Contributor
timestamp: November 03, 2019, 04:30:19 pm
content: well yes i coppied it direct from a web page,ive already got the librarys installed,any ideas on the error msg i got?

author: donotdespisethesnake
author_rank: Super Contributor
timestamp: November 03, 2019, 04:38:42 pm
content: If you copy and paste all the output from the compiler window, someone might be able to help.

author: m3vuv
author_rank: Super Contributor
timestamp: November 03, 2019, 04:56:43 pm
content: well i downloaded the same librarys and ide version as sokaloff used to compile it,this is what i get,see attached screenshot.

author: m3vuv
author_rank: Super Contributor
timestamp: November 03, 2019, 06:22:13 pm
content: heres a copy of the message i get,by the lack of replies i take it no one knows the issue!?Arduino: 1.8.3 (Windows 7), Board: "Arduino/Genuino Uno"C:\Users\me\Documents\Arduino\sketch_nov03a\sketch_nov03a.ino: In function 'void reverse(int)':sketch_nov03a:133: error: expected primary-expression before ')' tokenif (i < 1) break;)^sketch_nov03a:133: error: expected '}' at end of inputsketch_nov03a:133: error: expected '}' at end of inputexit status 1expected primary-expression before ')' tokenThis report would have more information with"Show verbose output during compilation"option enabled in File -> Preferences.

author: Mr. Scram
author_rank: Super Contributor
timestamp: November 03, 2019, 06:36:46 pm
content: It says what's wrong right in that error message. What you're trying to compile likely isn't what you posted here. Your local copy probably says "if (i < 1) break;)" instead of"if (i < 1) break;" Your ifs may need additional brackets too. I'm normally not one to point out spelling errors in thread titles but it's exactly those kinds of mistakes that gets you into trouble when writing code. Be careful and deliberate as a single character can screw you over. Also take heed of error messages as they tell you what's wrong or at least point you in the right direction.

author: Andy Watson
author_rank: Super Contributor
timestamp: November 03, 2019, 07:40:29 pm
content: Quote from: m3vuv on November 03, 2019, 06:22:13 pm133 is telling you the line number at which the compiler borks. In this case it appears to be the line after an "if ... break;" statement. For some reason there is a superfluous right-bracket at the end of the line.

author: StillTrying
author_rank: Super Contributor
timestamp: November 03, 2019, 07:43:25 pm
content: Who'd have guessed it would've turned out to be a typo.

author: m3vuv
author_rank: Super Contributor
timestamp: November 03, 2019, 08:26:11 pm
content: Strange but i copied and pasted it againe into the ide and it compiled and uploaded fine?,not sure why but who cares,job done,cheers m3vuv.

author: Mr. Scram
author_rank: Super Contributor
timestamp: November 03, 2019, 09:01:51 pm
content: Quote from: m3vuv on November 03, 2019, 08:26:11 pmWhy would that be unexpected? We told you what was wrong with your original code. You must have manually introduced the error we indicated. Now that you copied the code without that error it compiles correctly. Be sure to carefully assess what you're doing and make sure to take care of the details. Judging by this reply I fear you haven't learned from your mistake.

author: m3vuv
author_rank: Super Contributor
timestamp: November 12, 2019, 01:25:53 am
content: Finaly found the root cause of the issue,it was due to having 2 arduino tabs open!,may help others as im sure im not the onlyone had this problem,sometimes the answers so simple ppl miss it !!!

author: Mr. Scram
author_rank: Super Contributor
timestamp: November 12, 2019, 06:28:11 am
content: Quote from: m3vuv on November 12, 2019, 01:25:53 amThat's not what your compiler said. Why bother asking questions only to ignore the answers?

author: maginnovision
author_rank: Super Contributor
timestamp: November 12, 2019, 07:10:52 am
content: Quote from: Mr. Scram on November 12, 2019, 06:28:11 amI think it's actually his new hobby. Ask questions, demand prompt replies, then ignore everyone and say, "Nevermind! I figured it out myself!".

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 12, 2019, 08:23:08 pm
content: Quote from: Mr. Scram on November 12, 2019, 06:28:11 amYou must mean, "compoler"?