1

enter image description here

How do I start this program???

int x=0;
int P1=A5;
int P2=A4;
int P3=A3;
int R1=3;
int G1=5;
int B1=6;
int R2=9;
int G2=10;
int B2=11;
int sValue1;
int sValue2;
int sValue3;
int oValue1;
int oValue2;
int oValue3;
int timer(1000);

void setup() {
 pinMode(P1,INPUT);
 pinMode(P2,INPUT);
 pinMode(P3,INPUT);
 pinMode(R1,OUTPUT);
 pinMode(G1,OUTPUT);
 pinMode(B1,OUTPUT);
 pinMode(R2,OUTPUT);
 pinMode(G2,OUTPUT);
 pinMode(B2,OUTPUT); 

}

void loop() {

sValue1=analogRead(P1);
sValue2=analogRead(P2);
sValue3=analogRead(P3);

oValue1=map(sValue1,0,1023,0,255); 
oValue2=map(sValue2,0,1023,0,255);
oValue3=map(sValue3,0,1023,0,255);

if ((sValue1=0)&&(sValue2=0)&&(sValue3=0));
{
  setColor1(0,255,255);
  delay(timer);
  setColor2(255,0,0);
}
}

void setColor1(int red1, int green1, int blue1){
  {
    analogWrite(R1,red1);
    analogWrite(G1,green1);
    analogWrite(B1,blue1);
  }
}

void setColor2(int red2, int green2, int blue2){
  {
    analogWrite(R2,red2);
    analogWrite(G2,green2);
    analogWrite(B2,blue2);

  }
}
  • Also i get Error compiling from this program I started and I don't know what's wrong. – D3DSEC Mar 1 at 13:43
  • Welcome to SO. You should edit your question, select the entire block of code, and click the "format as code" button. (it looks like opening and closing curly braces, {}.) Unformatted code is really hard to read. (and never post more than a short code fragment in a comment since those don't line breaks.) – Duncan C Mar 1 at 13:47
  • What do you mean "how do I start this program?" Do you mean how do you install and run it on an Arduino? – Duncan C Mar 1 at 13:52
  • Now it has an error compiling for board. How do i fix this? – D3DSEC Mar 1 at 13:57
  • 1
    I think int timer(1000); should be int timer = 1000;. sValue1=0 should be sValue1==0, or to actually match the assignment's <=50%; sValue1<=127. – Gerben Mar 1 at 15:19
3

Arduino has created binary numbers: B1, B101, B00111, and so on.

It is documented in the reference page "Integer Constants".
The "B1" is defined in "binary.h".

They should not have done that. Not a single C++ software engineer thinks that it was a good addition. The C++ language is perfectly fine for creating binary values: 0b1, 0b101, 0b00111, and so on.

It is not your fault, you can blame Arduino. Because of this, you should never create variables with the name: B1, B101, B00111, and so on.

  • This sounds like the source of the error on that one line `int B1=6; Good callout. (Voted) – Duncan C Mar 1 at 22:14
0
  1. Install Arduino IDE
  2. New sketch
  3. Paste code
  4. Connect the Arduino board to your PC
  5. Upload sketch
0

Also i get Error compiling from this program

Obviously B1 is already defined as something, like your A5, A4 and A3 are.
You will very likely have the same issue with B2.

  • See Jot's answer. It sounds like B1 is the problem because apparently the Arduino library has some binary constants. like B1, B101, etc. – Duncan C Mar 1 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.