Chornelis

I have a program to control machine for ON-OFF power and expose lamp. I want, expose lamp running if condition power ON and expose cannot run if power OFF. This is my program :

int On_Pin = 6;
int Expose_Pin = 9;
String perintah;
int len;
int tempInt;
int tunda1;

void setup()
{
Serial.begin(9600);
pinMode(On_Pin, OUTPUT);
digitalWrite(On_Pin, HIGH);
pinMode(Expose_Pin, OUTPUT);
digitalWrite(Expose_Pin, HIGH);
tunda1=1000;
}

void loop()
{
if (Serial.available()>0){
char buffer [10];

len = Serial.readBytesUntil('=', buffer, 10);

buffer[len] = '\0';
perintah = buffer;
tempInt = not (Serial.parseInt());

perintah.trim();
if (perintah == "i"){
digitalWrite(On_Pin, tempInt);}
else if ((perintah == "i=1") && (perintah == "e")){
digitalWrite(Expose_Pin, LOW);
delay(tunda1);
digitalWrite(Expose_Pin, HIGH);
perintah = "";}
}
}

what wrong with my program? Thanks before :slight_smile:

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Chornelis:
what wrong with my program?

Why don't you tell us? What do you expect it to do? What is it doing instead of what you expect? If you are encountering error messages then post them, also using code tags.

  tempInt = not (Serial.parseInt());

WTF?

 len = Serial.readBytesUntil('=', buffer, 10);   
   
    buffer[len] = '\0';
    perintah = buffer;
    tempInt = not (Serial.parseInt());
   
    perintah.trim();
    if (perintah == "i"){
      digitalWrite(On_Pin, tempInt);}
    else if ((perintah == "i=1") && (perintah == "e")){

Since you stop reading data when the '=' arrives, there isn't a snowball's chance in hell that pertinah will ever equal "i=1".

Even if it did, there is no way that pertinah will ever equal "i-1" and "e" at the same time, so you might as well just delete the else if statement and the whole block that follows it, as that code will never be executed.

@Chornelis - the purpose of the title is to give people an idea of what the problem is so that those who can help will look at your Thread and those who can't won't waste their time. Repeating your name in the title is no help.

You can change the title if you modify your Original Post

...R

Robin2:
@Chornelis - the purpose of the title is to give people an idea of what the problem is so that those who can help will look at your Thread and those who can't won't waste their time. Repeating your name in the title is no help.

it made me curious to look... mission accomplished.