Go Down

Topic: Error Message in Code (Read 285 times) previous topic - next topic

Jariana

Jul 20, 2018, 11:59 pm Last Edit: Jul 21, 2018, 12:09 am by Jariana
I am not understanding why I am receiving an error message for the portion of my code that is "highlighted" in red.  This is my first time writing code by myself and I am unable to interrupt what the error message is saying to me and how to fix it. The error message reads at the bottom of this post, underneath my code.  Can anyone help me, please?

int h[2]= {0000, 0001};

int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;

int s02 = 7;
int s12 = 6;
int s22 = 5;
int s32 = 4;


void setup() {
 
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);

pinMode(s02, OUTPUT);
pinMode(s12, OUTPUT);
pinMode(s22, OUTPUT);
pinMode(s32, OUTPUT);

Serial.begin(9600);

}

void loop() {
  int val = analogRead(0);
 
for (int i = 1:2)
  r1 = h(i,1)
  r2 = h(i,2)
  r3 = h(i,3)
  r4 = h(i,4)
 
for j = 1:2
  r5 = h(i,5)
  r6 = h(i,6)
  r7 = h(i,7)
  r8 = h(i,8)

digitalWrite(s0, r1)
digitalWrite(s1, r2)
digitalWrite(s2, r3)
digitalWrite(s3, r4)

digitalWrite(s02, r5)
digitalWrite(s12, r6)
digitalWrite(s22, r7)
digitalWrite(s32, r8)

end
end

  Serial.print("Value at channel: ");
  Serial.print(val);
  delay(1000);

}

Code: [Select]
int h[2]= {0000, 0001};

int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;

int s02 = 7;
int s12 = 6;
int s22 = 5;
int s32 = 4;


void setup() {
 
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);

pinMode(s02, OUTPUT);
pinMode(s12, OUTPUT);
pinMode(s22, OUTPUT);
pinMode(s32, OUTPUT);

Serial.begin(9600);

}

void loop() {
  int val = analogRead(0);
 
for (int i = 1:2)
  r1 = h(i,1)
  r2 = h(i,2)
  r3 = h(i,3)
  r4 = h(i,4)
 
for j = 1:2
  r5 = h(i,5)
  r6 = h(i,6)
  r7 = h(i,7)
  r8 = h(i,8)

digitalWrite(s0, r1)
digitalWrite(s1, r2)
digitalWrite(s2, r3)
digitalWrite(s3, r4)

digitalWrite(s02, r5)
digitalWrite(s12, r6)
digitalWrite(s22, r7)
digitalWrite(s32, r8)

end
end

  Serial.print("Value at channel: ");
  Serial.print(val);
  delay(1000);

}




ERROR:

/tmp/907409201/sketch_jul13a/sketch_jul13a.ino: In function 'void loop()':

/tmp/907409201/sketch_jul13a/sketch_jul13a.ino:39:3: error: 'r1' was not declared in this scope

/tmp/907409201/sketch_jul13a/sketch_jul13a.ino:39:13: error: 'h' cannot be used as a function

exit status 1

AWOL

#1
Jul 22, 2018, 08:58 am Last Edit: Jul 22, 2018, 09:01 am by AWOL
Code: [Select]
for (int i = 1:2)You really need to take a look at some of the worked examples in the IDE, paying particular attention to for loops, arrays, and {} braces (and scope).

Also, the e-textiles forum is not the most appropriate for this question - I'll move it to programming.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

UKHeliBob

Code: [Select]

  r1 = h(i,1)
  r2 = h(i,2)
  r3 = h(i,3)
  r4 = h(i,4)

Just few missing semicolons ...
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

PieterP

C++ is not Python. You have to follow the correct syntax. You have to declare your variables. You have to use braces around code  blocks. You have to use  semicolons. Please look up how to use for loops.

Pieter

PaulMurrayCbr

Ok. Your code is not actually valid C++ code. You need to go do a C++ tutorial and learn the syntax of the language.

Here's one: http://www.cplusplus.com/doc/tutorial/ .
http://paulmurraycbr.github.io/ArduinoTheOOWay.html

Go Up