Author Topic: why wont this compole?  (Read 2252 times)

0 Members and 3 Guests are viewing this topic.

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
why wont this compole?
« on: November 03, 2019, 03:22:50 pm »
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.htm
Arduino Stepper Motor Coil Winder
Lewis Loflin
lewis@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 0x27

int i, j;

void setup()  {

  pinMode(SW0, INPUT);
  pinMode(SW1, INPUT);
  pinMode(SW2, INPUT);
  pinMode(SW3, INPUT);

  digitalWrite(SW0, 1); // pull up on
  digitalWrite(SW1, 1); // pull up on
  digitalWrite(SW2, 1);
  digitalWrite(SW3, 1);

  lcd.init(); // initialize the lcd
  lcd.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 seconds
  lcd.setCursor(0, 1); // is Home
  lcd.print("Ready to go!");

  j = 0;

}

void loop() {

  // set turns
  if (!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 while
    lcd.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 loop


void 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.
 

Offline sokoloff

  • Super Contributor
  • ***
  • Posts: 1799
  • Country: us
Re: why wont this compole?
« Reply #1 on: November 03, 2019, 03:31:40 pm »
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 people
LiquidCrystal_I2C - v1.1.12 by Frank de Brabander
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: why wont this compole?
« Reply #2 on: November 03, 2019, 03:34:34 pm »
@sokoloff beat me to it, but compiles fine here on Arduino 1.8.3 with the additional libraries installed.
Bob
"All you said is just a bunch of opinions."
 

Offline Andy Watson

  • Super Contributor
  • ***
  • Posts: 2112
Re: why wont this compole?
« Reply #3 on: November 03, 2019, 04:24:57 pm »
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.
 

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
Re: why wont this compole?
« Reply #4 on: November 03, 2019, 04:30:19 pm »
well yes i coppied it direct from a web page,ive already got the librarys installed,any ideas on the error msg i got?
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: why wont this compole?
« Reply #5 on: November 03, 2019, 04:38:42 pm »
If you copy and paste all the output from the compiler window, someone might be able to help.
Bob
"All you said is just a bunch of opinions."
 

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
Re: why wont this compole?
« Reply #6 on: November 03, 2019, 04:56:43 pm »
well i downloaded the same librarys and ide version as sokaloff used to compile it,this is what i get,see attached screenshot.
 

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
Re: why wont this compole?
« Reply #7 on: November 03, 2019, 06:22:13 pm »
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 ')' token

     if (i < 1) break;)

                      ^

sketch_nov03a:133: error: expected '}' at end of input

sketch_nov03a:133: error: expected '}' at end of input

exit status 1
expected primary-expression before ')' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
 

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: why wont this compole?
« Reply #8 on: November 03, 2019, 06:36:46 pm »
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.
« Last Edit: November 03, 2019, 06:38:17 pm by Mr. Scram »
 

Offline Andy Watson

  • Super Contributor
  • ***
  • Posts: 2112
Re: why wont this compole?
« Reply #9 on: November 03, 2019, 07:40:29 pm »
sketch_nov03a:133: error: expected primary-expression before ')' token

     if (i < 1) break;)

                      ^

sketch_nov03a:133: error: expected '}' at end of input

133 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.
 
The following users thanked this post: Mr. Scram

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: why wont this compole?
« Reply #10 on: November 03, 2019, 07:43:25 pm »
Who'd have guessed it would've turned out to be a typo. >:D
.  That took much longer than I thought it would.
 
The following users thanked this post: Mr. Scram

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
Re: why wont this compole?
« Reply #11 on: November 03, 2019, 08:26:11 pm »
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.
 

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: why wont this compole?
« Reply #12 on: November 03, 2019, 09:01:51 pm »
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.
Why 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.
 
The following users thanked this post: Dielectric

Offline m3vuvTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 1738
  • Country: gb
Re: why wont this compole?
« Reply #13 on: November 12, 2019, 01:25:53 am »
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 !!!
 

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: why wont this compole?
« Reply #14 on: November 12, 2019, 06:28:11 am »
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 !!!
That's not what your compiler said. Why bother asking questions only to ignore the answers?
 

Offline maginnovision

  • Super Contributor
  • ***
  • Posts: 1966
  • Country: us
Re: why wont this compole?
« Reply #15 on: November 12, 2019, 07:10:52 am »
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 !!!
That's not what your compiler said. Why bother asking questions only to ignore the answers?

I think it's actually his new hobby. Ask questions, demand prompt replies, then ignore everyone and say, "Nevermind! I figured it out myself!".
 
The following users thanked this post: Mr. Scram

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15215
  • Country: fr
Re: why wont this compole?
« Reply #16 on: November 12, 2019, 08:23:08 pm »
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 !!!
That's not what your compiler said.

You must mean, "compoler"? ;D
 
The following users thanked this post: Mr. Scram


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf