Results 1 to 5 of 5
  1. #1
    10+ Posting Member
    Join Date
    Jan 2013
    Location
    canada
    Posts
    14
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Mycockpit.org Arduino Stall warning audio...i need help

    i am new to programming and i am teaching myself. i am trying to get a speaker to play a specific tone/note when Link2fs in out reads Stall Warning "HIGH". The code that i have written so far sound as if its reading links2fs info but not playing note/tone; i hear a low noise tic almost like when u use a battery on a speaker.
    here is my code:

    int speakerPin = 9;
    int j1;
    int length = 2; // the number of notes
    char notes[] = "C C "; // a space represents a rest
    int beats[] = { 3, 3 };
    int tempo = 300;


    String StallW, StallWOld;


    void playTone(int tone, int duration) {
    for (long i = 0; i < duration * 1000L; i += tone * 2) {
    if (Serial.available() > 0) {
    j1 = Serial.read();
    if(j1 == 'L') {
    delay(11);
    StallW = "";
    StallW += (char)Serial.read();
    if(StallW != StallWOld){
    if(StallW == "1")
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    if(StallW == "0")
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
    }
    StallWOld = StallW;
    }
    }
    }
    }


    void playNote(char note, int duration) {
    char names[] = { 'C', 'C' };
    int tones[] = { 956, 956 };
    // play tone corresponding to the note name
    for (int i = 0; i < 2; i++) {
    if (names[i] == note) {
    playTone(tones[i], duration);
    }
    }
    }


    void setup() {
    Serial.begin(115200);
    {
    pinMode(speakerPin, OUTPUT);

    Serial.flush();
    }
    }


    void loop() {
    for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
    delay(beats[i] * tempo); // rest
    } else {
    playNote(notes[i], beats[i] * tempo);
    }
    // pause between notes
    delay(tempo / 2); }
    }



    here is where i got the idea to use note/tone to play when stall warning HIGH.(UPLOAD THIS CODE TO TEST THE SOUND WITH SPEAKER/PIEZO ATTACH TO PIN 9 AND GROUND)
    int speakerPin = 9;


    int length = 2; // the number of notes
    char notes[] = "C C "; // a space represents a rest
    int beats[] = { 3, 3 };
    int tempo = 300;


    void playTone(int tone, int duration) {
    for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
    }
    }


    void playNote(char note, int duration) {
    char names[] = { 'C', 'C' };
    int tones[] = { 956, 956 };
    // play tone corresponding to the note name
    for (int i = 0; i < 2; i++) {
    if (names[i] == note) {
    playTone(tones[i], duration);
    }
    }
    }


    void setup() {
    pinMode(speakerPin, OUTPUT);
    }


    void loop() {
    for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
    delay(beats[i] * tempo); // rest
    } else {
    playNote(notes[i], beats[i] * tempo);
    }
    // pause between notes
    delay(tempo / 2); }
    }

  2. #2
    500+ This must be a daytime job Jim NZ's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    764
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino Stall warning audio...i need help

    I'm terrible at fiddling with some-one else's code but after quick look ,, one thing that jumped out at me was the serial com.s stuff was in the wrong place.
    It should be in the "void loop" as that's the 'main' loop that everything happens from.
    So have a shuffle around with that and see if you can't make it happen.
    I could be wrong though as I haven't solidly studied the code.

    Another thing to think about is with Arduino doing all the "oscillating" for the speaker ,,, is ,, while it's doing that, it's not doing other stuff. That's fine though as long as the cards not going to be busy doing other stuff.

    Cheers ,,, Jim
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !

  3. #3
    10+ Posting Member
    Join Date
    Jan 2013
    Location
    canada
    Posts
    14
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino Stall warning audio...i need help

    i have tried it before in void loop, and it didnt work. i will give it a next try. maybe it was the way i rearranged it before. thanks for your suggestion i will keep you posted and let u know if it works....
    i am updating my falcon 7x flight sim. BIG THANKS to the softwares on ur webpage it made most things possible to simulate and now i dont have to buy expensive sim hardware. i can now make everything completely from scratch... Attachment 7940Attachment 7941Attachment 7942

    thats what my sim looks like now going update MCP, glareshield, overhead, radiostack, and add an annuciator panel with ur software.

    cheers and thanks alot ....Mario

  4. #4
    10+ Posting Member
    Join Date
    Jan 2013
    Location
    canada
    Posts
    14
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino Stall warning audio...i need help

    hey jim
    good news i got it to work.....bbbbuuuuuuuuttttt!!!!! the audio does not play for the duration of the stall in fsx. its plays when aircraft stall but only up to the calculated point in the code then it stops..... im at the point where i am trying to figure out how to keep audio signal for duration of the stall.

    int speakerPin = 9;
    int j1;
    int length = 1; // the number of notes
    char notes[] = "C"; // a space represents a rest
    int beats[] = { 9 };
    int tempo = 300;
    int i;




    String StallW, StallWOld;


    void playTone(int tone, int duration) {
    for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
    }
    }


    void playNote(char note, int duration) {
    char names[] = { 'C' };
    int tones[] = { 956 };
    // play tone corresponding to the note name
    for (int i = 0; i < 1; i++) {
    if (names[i] == note) {
    playTone(tones[i], duration);
    }
    }
    }


    void setup() {
    Serial.begin(115200);
    {
    pinMode(speakerPin, OUTPUT);


    }
    }
    void loop() {
    if (Serial.available() > 0) {
    j1 = Serial.read();
    if(j1 == 'L') {
    delay(11);
    StallW = "";
    StallW += (char)Serial.read();
    if(StallW != StallWOld){
    if(StallW == "1"){
    playNote(notes[i], beats[i] * tempo);
    delay(11);

    if(StallW == "0")
    digitalWrite(speakerPin, LOW);
    delay(11);
    }
    StallWOld = StallW;
    }
    }
    }
    }


    i know so far that "beats[i] * tempo" determines the duration after audio signal is triggered. i have tried multiple ways to change duration none seem to work yet. i will keep on trying until i figure it out. next step i will try is to remove "int duration" out of the code.

  5. #5
    10+ Posting Member
    Join Date
    Jan 2013
    Location
    canada
    Posts
    14
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino Stall warning audio...i need help

    all problems are solved i have rewritten the program, much more simple than above codes and it works excellent...

Tags for this Thread