My code doesn't work

Hello, I was coding for a telegraph in web editor, but code doesnt work. The code is here:

int kont = 2;
int yazi[100];

void setup() {
  pinMode(kont, INPUT);
  Serial.begin(9600);
}

void loop() {
  for(int i = 0; i<101; i++){
    int ba=digitalRead(kont);
    if ba == 1{
      delay(200);
      if ba == 0{
        yazi[i] = 0;
        Serial.print(yazi[i]);
      }
      else{
        yazi[i] = 1;
        Serial.print(yazi[i]);
      }
    }
  }
  
}

And also the terminal:

/tmp/568693805/sketch_jun10c/sketch_jun10c.ino: In function 'void loop()':

/tmp/568693805/sketch_jun10c/sketch_jun10c.ino:12:8: error: expected '(' before 'ba'

if ba == 1{

^~

Error during build: exit status 1

I am sure with connections, but still doesnt working.

C language requires brackets () around the boolean expression in an 'if' statement.

Hi, @yekta_ino
Welcome to the forum.

What model Arduino are you using?

Can you please tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

like this?

if ba = 1(){
   delay(9999);
}

I am using uno, I am not proffesional in Arduino but I had a simple education

if (b == 1)
{...}

thanks

Hi,

Have you programed an Arduino before?

What model Arduino are you using?

Thanks... Tom.. :smiley: :+1: :coffee: :australia:

If it wasn't zero 200 milliseconds ago, its value is unlikely to have changed.

If ba equals 1 it can never equal 0 at the same time then the second comparison will never be true.

int yazi[100]; // reserves 100 addresses
...
for(int i=0; i<101; i++) // counts 101 numbers

I respect your knowledge on all subjects, @anon57585045, but may I sxy this:
() parentheses
[] brackets
{} braces

3 Likes

{}[]()

The set of brackets, made up of subsets curly, square, and round.

Ha. No.

"parenthetically" is not "round bracketly," et cetera, ibid.
Those terms are taught to those who can not remember or correctly pronounce words easily.
[edit] ... but this is not meant to point at you... it is pointed at whomever taught your teachers.

Oh, I'm fully with you, should have winked as part of the comment. That came from my nephew's school. Sigh.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.