0
/*aim of the program is to generate 2 different varying frequency from the
same output which is controlled by 2 triggers*/
void setup()
{
    pinMode(2,INPUT); //setting the trigger pins 2,3
    pinMode(3,INPUT);
    pinMode(6,OUTPUT); //output pin
}

void loop()
{
    if(digitalRead(2)==HIGH && digitalRead(3)==LOW) { //trigger conditions
        infra();
    }
    else if(digitalRead(2)==LOW && digitalRead(3)==HIGH) {
        red();
    }
    else if((digitalRead(2)==HIGH && digitalRead(3)==HIGH) || (digitalRead(2)==LOW && digitalRead(3)==LOW)) {
        Serial.println('help');
    }
}

void infra() //function varies sinosoidaly (working)
{
    float f;

    for(f=16000; f<=20525; f+=4.525) {
        tone(6,f);
    }

    for(f=20525; f>=16000; f=f-4.525) {
        tone(6,f);
    }
}

void red() //function varies sinosoidaly (working)
{
    float p;

    for(p=25000; p<=32071; p+=7.071) {
        tone(6,p);
    }

    for(p=32071; p>=25000; p=p-7.071) {
        tone(6,p);
    }
}
6
  • The third if is unnecesary. – user31481 Jan 24 '18 at 21:59
  • 1
    'Fails' means your code never print "help"?. You code never initialize Serial to start with ... – user31481 Jan 24 '18 at 22:02
  • 3
    'help' is not a string. – gre_gor Jan 24 '18 at 22:29
  • the code fails to generate the values i want ... how does it fail? – jsotola Jan 25 '18 at 1:36
  • @gre_gor I think you have found the problem. Would you care to turn your comment into an answer? – per1234 Jan 25 '18 at 9:05
2

To send anything to serial you need to initialize it first with:

void setup()
{
    Serial.begin(115200);
    //other code
}

And you are using wrong quotes for the string.
They should be double quotes " not single ones '.

Also you could simplify your code, if you removed the third if, since it's just checking the already known state at that point.

You should also read the button state only once, save them into a variable and then just compare those variables.

bool button1_state = digitalRead(2);
bool button2_state = digitalRead(3);
if (button1_state && !button2_state) {
    infra();
}
else if (!button1_state && button2_state) {
    red();
}
else {
    Serial.println("help");
}

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