Author Topic: problem with arduino code  (Read 2363 times)

0 Members and 1 Guest are viewing this topic.

Offline little_carlosTopic starter

  • Regular Contributor
  • *
  • Posts: 134
problem with arduino code
« on: May 15, 2015, 05:12:12 pm »
hello guys, im trying to do a digital counter, from 1 to 128, but i get an error, this one, could someone tell me what is it
int n = 0                       
int 1 = 3
int 2 = 4
int 4 = 5
int 8 = 6
int 16 = 7
int 32 = 8
int 64 = 9
int 128 = 10
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
void setup() {
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(16, OUTPUT);
  pinMode(32, OUTPUT);
  pinMode(64, OUTPUT);
  pinMode(128, OUTPUT);
}

void loop() {
  a = n;
  digitalWrite(1, a%2);
  b = a/2;
  digitalWrite(2, b%2);
  c = b/2;
  digitalWrite(4, c%2);
  d = c/2;
  digitalWrite(8, d%2);
  e = d/2;
digitalWrite(16, e%2);
  f = e/2;
  digitalWrite(32, f%2);
  g = f/2;
  digitalWrite(64, g%2);
  h = g/2;
  digitalWrite(128, h%2);
}

the error is :
Arduino:1.6.0 (Windows 7), Placa:"Arduino Uno"



sketch_may15a.ino:2:1: error: expected ',' or ';' before 'int'
sketch_may15a.ino: In function 'void loop()':
sketch_may15a.ino:30:3: error: 'a' was not declared in this scope
Error de compilaciĆ³n
 

Offline ctz

  • Contributor
  • Posts: 26
  • Country: gb
Re: problem with arduino code
« Reply #1 on: May 15, 2015, 05:20:11 pm »
- numbers aren't valid identifiers in C++.
- statements end in a semicolon. you have some of these, but some are missing.

as a style issue, you probably don't want a-h to be globals. declare them inside loop().
 

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: 00
Re: problem with arduino code
« Reply #2 on: May 15, 2015, 07:08:26 pm »
Give some background in what you are looking to and we will be able to help you fix your problems.
Try to include:
  • What you are trying to achieve
  • What each pin does
  • What board you are using
  • Add comments in your code saying what each line does, what you are defining etc.
  • Please try to use the "[ code][ /code]" tag to make it look clean
Code: [Select]
It will be formatted like this. It makes it easier to read
     

    Offline tron9000

    • Frequent Contributor
    • **
    • Posts: 423
    • Country: gb
    • Still an Electronics Lab Tech
      • My Hack-a-day project page
    Re: problem with arduino code
    « Reply #3 on: May 15, 2015, 10:21:18 pm »
    - numbers aren't valid identifiers in C++.
    +1 this
    Partsbox.io - orangise your parts!
    "If you're green you can only ripen. If you're ripe you can only rot!"
     

    Offline zapta

    • Super Contributor
    • ***
    • Posts: 6289
    • Country: 00
    Re: problem with arduino code
    « Reply #4 on: May 15, 2015, 11:52:17 pm »
    You can simplify the code by listing the pounds in an array of IBT and then update then in a loop, one pin at a time.

    (Reading on my phone, can't write sample code)
     


    Share me

    Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
    Smf