Results 1 to 2 of 2
  1. #1
    10+ Posting Member
    Join Date
    Nov 2011
    Location
    Rotorua, New Zealand
    Posts
    10
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Link2fs Announciator panel

    Hi

    I've been trying to add some code into the announciator pde that will light up all the outputs with the push of a momentary button.
    I want to use this as a test button like in most aircraft so you can test the LED's and Pizo before start up.
    Here is some code that works great by itself but I am not quite skilled enough to work out how so add it into Jim's announciator pde to make this work.

    Can anybody help?

    here is the code from Arduino site to make LED light up without having to use a pullup resistor.

    //This example code is in the public domain

    void setup() {
    //start serial connection
    Serial.begin(9600);
    //configure pin2 as an input and enable the internal pull-up resistor
    pinMode(2, INPUT_PULLUP);
    pinMode(13, OUTPUT);

    }

    void loop() {
    //read the pushbutton value into a variable
    int sensorVal = digitalRead(2);
    //print out the value of the pushbutton
    Serial.println(sensorVal);

    // Keep in mind the pullup means the pushbutton's
    // logic is inverted. It goes HIGH when it's open,
    // and LOW when it's pressed. Turn on pin 13 when the
    // button's pressed, and off when it's not:
    if (sensorVal == HIGH) {
    digitalWrite(13, LOW);
    }
    else {
    digitalWrite(13, HIGH);
    }
    }


    Fixed thanks to BushPilotWonnabe.
    Feel free to try.

    /*
    Re: re. Link2fs Announciator panel 7 lights and 2 pushbutton
    Push-To-Test Switch added by BushPilotWannabe July 2015
    MOVE THE COMMENT MARKERS from line#2 to line#3
    test using FSX C172SP Skyhawk audio panel and Link2FS Extractions1 boxes N, O, P, Q, U, R & S
    both void SLASH() and void EQUALS() can be left intact. The input from Link2FS Extractions determines the output
    */


    int AnunPinNo[7] = {2, 3, 4, 5, 6, 7, 8};// the selected pins with LED's
    // char AnunIdent2[7] = {'E','F','L','Q','V','b','f'};//Selected items in "Annunciators" in Multi
    char AnunIdent2[7] = {'N','O','P','Q','U','R','S'};
    long AnunButtonStop = 0;
    boolean ButtonStopEnable = 0;
    //
    int AnunPinValNew[7] = {0,0,0,0,0,0,0};//Array for pin values (The new readings)
    int AnunPinValOld[7] = {0,0,0,0,0,0,0};//Array for pin values (The old readings)
    int count = 0; //for array reading
    int counterTrigger = 0;// Used for triggering the flashing LED's
    int counterTriggerOld = 0;
    long counter = 1; // Counter for read loops TO TIME THE FLASHING
    int CodeIn;// Gets the serial read
    int PTTButton = 10;
    int bipassSwitchPins = 0; // =1 avoids repetitive pin assignments
    int piezo = 11;//Was 11
    int dummy; // dummy output until LEDs are restored after test
    int Anunbutton = 12;// the cancell alarm button in the Annunciator panel
    int AnunPinTot = 0;//Used for cancelling alarms if fault disappears before pushing button






    void setup(){
    for (count=0;count<7;count++) {// we make all the Anun declarations at once
    // Be careful with the above line.(Dont involve a pin that will have a switch on it ,, it can fry your pin or card)
    pinMode(AnunPinNo[count], OUTPUT);
    digitalWrite(AnunPinNo[count], LOW);
    }
    pinMode(PTTButton,INPUT_PULLUP);
    digitalWrite(PTTButton,HIGH);
    pinMode(piezo, OUTPUT); // done the piezo seperately for clearer coding
    digitalWrite(piezo, LOW);
    pinMode(Anunbutton, INPUT_PULLUP); // Cancell button on Anunnciators
    pinMode(dummy,OUTPUT);
    digitalWrite(Anunbutton, HIGH);
    Serial.begin(115200);
    }




    void loop() {
    {OTHER();}
    {ANNUNBUTTON();}
    {PUSHTOTEST();}
    if (Serial.available()) {
    CodeIn = getChar();
    if (CodeIn == '=') {EQUALS();}
    if (CodeIn == '<') {LESSTHAN();}
    if (CodeIn == '?') {QUESTION();}
    if (CodeIn == '/') {SLASH();}
    }
    }




    char getChar()
    {
    while(Serial.available() == 0);
    return((char)Serial.read());
    }




    void OTHER(){
    // Normal "run" stuff in here
    }




    void EQUALS(){
    CodeIn = getChar();
    AnunPinTot = 0; // for turning OFF piezo after quick fault
    for (count=0;count<7;count++) {
    if (CodeIn == AnunIdent2[count]){
    AnunPinValNew[count] = (getChar()- 4;
    if (AnunPinValNew[count] == 1){
    if (AnunPinValOld[count] < 1) {digitalWrite(AnunPinNo[count], HIGH);
    digitalWrite(piezo, HIGH);
    AnunPinValOld[count] = AnunPinValNew[count];}}
    if (AnunPinValNew[count] == 0){
    if (AnunPinValOld[count] > 0) {digitalWrite(AnunPinNo[count], LOW);AnunPinValOld[count] = AnunPinValNew[count];
    }}}
    if (AnunPinValOld[count] < 2 ){// for turning OFF piezo after quick fault
    AnunPinTot = (AnunPinTot + AnunPinValNew[count]);}
    //Serial.print(PinValNew[count]);
    }
    if (AnunPinTot < 1) {digitalWrite(piezo, LOW); } // for turning OFF piezo after quick fault
    }


    /*
    CodeIn = getChar();
    switch(CodeIn) {
    case 'A':
    //Do something
    break;


    case 'W':
    //Do something
    break;


    case 'a':
    //Do something
    break;
    //etc etc etc
    }
    }
    */




    void LESSTHAN(){ // The first identifier was "<"
    //Do something (See void EQUALS)
    }




    void QUESTION(){ // The first identifier was "?"
    //Do something (See void EQUALS)
    }




    void SLASH(){ // The first identifier was "/" (Annunciators)
    CodeIn = getChar();
    AnunPinTot = 0; // for turning OFF piezo after quick fault
    for (count=0;count<7;count++) {
    if (CodeIn == AnunIdent2[count]){
    AnunPinValNew[count] = (getChar()- 4;
    if (AnunPinValNew[count] == 1){
    if (AnunPinValOld[count] < 1) {digitalWrite(AnunPinNo[count], HIGH);
    digitalWrite(piezo, HIGH);
    AnunPinValOld[count] = AnunPinValNew[count];}}
    if (AnunPinValNew[count] == 0){
    if (AnunPinValOld[count] > 0) {digitalWrite(AnunPinNo[count], LOW);AnunPinValOld[count] = AnunPinValNew[count];
    }}}
    if (AnunPinValOld[count] < 2 ){// for turning OFF piezo after quick fault
    AnunPinTot = (AnunPinTot + AnunPinValNew[count]);}
    //Serial.print(PinValNew[count]);
    }
    if (AnunPinTot < 1) {digitalWrite(piezo, LOW); } // for turning OFF piezo after quick fault
    }




    void ANNUNBUTTON(){
    counter = counter + 1;
    if (counter < 50000){counterTrigger = 0;}else {counterTrigger = 1;}
    if (counter > 100000) {counter = 1;}
    if (digitalRead(Anunbutton)==0){
    digitalWrite(piezo, LOW);
    for (count=0;count<7;count++) {
    if (AnunPinValOld[count] == 1){AnunPinValOld[count] = 3;}
    }
    }
    if (counterTrigger != counterTriggerOld) {
    for (count=0;count<7;count++) {
    if (AnunPinValOld[count] == 3) {
    if (counterTrigger == 1){digitalWrite(AnunPinNo[count], HIGH);}
    if (counterTrigger == 0){digitalWrite(AnunPinNo[count], LOW);}
    }
    }
    counterTriggerOld = counterTrigger;
    }
    }






    void PUSHTOTEST()
    {
    if (digitalRead(10)==0){
    if (bipassSwitchPins != 1){
    for (count=0; count<7;count++) {AnunPinNo[count] =13; }
    piezo = 13;
    for (count=2; count<9; count++) digitalWrite(count,HIGH);
    digitalWrite(11,HIGH);
    bipassSwitchPins = 1;
    }
    AnunButtonStop = millis() + 400;
    ButtonStopEnable = 1;
    }
    // cleanup
    if (((millis()) > AnunButtonStop) && ButtonStopEnable == 1){
    for (count=2; count<9; count++) {digitalWrite(count,LOW); }
    {digitalWrite(11,LOW); digitalWrite(13,LOW);}
    {AnunPinNo[0] = 2; AnunPinNo[1] = 3; AnunPinNo[2] = 4; AnunPinNo[3] = 5;}
    {AnunPinNo[4] = 6; AnunPinNo[5] = 7; AnunPinNo[6] = 8;}
    piezo= 11;
    for (count=0;count<7;count++) {
    if (AnunPinValOld[count] == 1) {digitalWrite(AnunPinNo[count],AnunPinValOld[count]); digitalWrite(piezo,HIGH);}
    {ButtonStopEnable = 0; bipassSwitchPins = 0;} // remove enable keys on exit
    }
    }
    }




  2. #2
    10+ Posting Member
    Join Date
    Nov 2011
    Location
    Rotorua, New Zealand
    Posts
    10
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Link2fs Announciator panel

    All sorted thanks to BushPilotWannabe help.

    Also check out my progress site crescoproject.wordpress.com on how my Simulator is coming along and for info on how I have got things running.

    Feel free to try the arduino sketch blow using Jim's link2fs.

    /*
    Re: re. Link2fs Announciator panel 7 lights and 2 pushbutton
    Push-To-Test Switch added by BushPilotWannabe July 2015
    MOVE THE COMMENT MARKERS from line#2 to line#3
    test using FSX C172SP Skyhawk audio panel and Link2FS Extractions1 boxes N, O, P, Q, U, R & S
    both void SLASH() and void EQUALS() can be left intact. The input from Link2FS Extractions determines the output
    */


    int AnunPinNo[7] = {2, 3, 4, 5, 6, 7, 8};// the selected pins with LED's
    // char AnunIdent2[7] = {'E','F','L','Q','V','b','f'};//Selected items in "Annunciators" in Multi
    char AnunIdent2[7] = {'N','O','P','Q','U','R','S'};
    long AnunButtonStop = 0;
    boolean ButtonStopEnable = 0;
    //
    int AnunPinValNew[7] = {0,0,0,0,0,0,0};//Array for pin values (The new readings)
    int AnunPinValOld[7] = {0,0,0,0,0,0,0};//Array for pin values (The old readings)
    int count = 0; //for array reading
    int counterTrigger = 0;// Used for triggering the flashing LED's
    int counterTriggerOld = 0;
    long counter = 1; // Counter for read loops TO TIME THE FLASHING
    int CodeIn;// Gets the serial read
    int PTTButton = 10;
    int bipassSwitchPins = 0; // =1 avoids repetitive pin assignments
    int piezo = 11;//Was 11
    int dummy; // dummy output until LEDs are restored after test
    int Anunbutton = 12;// the cancell alarm button in the Annunciator panel
    int AnunPinTot = 0;//Used for cancelling alarms if fault disappears before pushing button






    void setup(){
    for (count=0;count<7;count++) {// we make all the Anun declarations at once
    // Be careful with the above line.(Dont involve a pin that will have a switch on it ,, it can fry your pin or card)
    pinMode(AnunPinNo[count], OUTPUT);
    digitalWrite(AnunPinNo[count], LOW);
    }
    pinMode(PTTButton,INPUT_PULLUP);
    digitalWrite(PTTButton,HIGH);
    pinMode(piezo, OUTPUT); // done the piezo seperately for clearer coding
    digitalWrite(piezo, LOW);
    pinMode(Anunbutton, INPUT_PULLUP); // Cancell button on Anunnciators
    pinMode(dummy,OUTPUT);
    digitalWrite(Anunbutton, HIGH);
    Serial.begin(115200);
    }




    void loop() {
    {OTHER();}
    {ANNUNBUTTON();}
    {PUSHTOTEST();}
    if (Serial.available()) {
    CodeIn = getChar();
    if (CodeIn == '=') {EQUALS();}
    if (CodeIn == '<') {LESSTHAN();}
    if (CodeIn == '?') {QUESTION();}
    if (CodeIn == '/') {SLASH();}
    }
    }




    char getChar()
    {
    while(Serial.available() == 0);
    return((char)Serial.read());
    }




    void OTHER(){
    // Normal "run" stuff in here
    }




    void EQUALS(){
    CodeIn = getChar();
    AnunPinTot = 0; // for turning OFF piezo after quick fault
    for (count=0;count<7;count++) {
    if (CodeIn == AnunIdent2[count]){
    AnunPinValNew[count] = (getChar()- 4;
    if (AnunPinValNew[count] == 1){
    if (AnunPinValOld[count] < 1) {digitalWrite(AnunPinNo[count], HIGH);
    digitalWrite(piezo, HIGH);
    AnunPinValOld[count] = AnunPinValNew[count];}}
    if (AnunPinValNew[count] == 0){
    if (AnunPinValOld[count] > 0) {digitalWrite(AnunPinNo[count], LOW);AnunPinValOld[count] = AnunPinValNew[count];
    }}}
    if (AnunPinValOld[count] < 2 ){// for turning OFF piezo after quick fault
    AnunPinTot = (AnunPinTot + AnunPinValNew[count]);}
    //Serial.print(PinValNew[count]);
    }
    if (AnunPinTot < 1) {digitalWrite(piezo, LOW); } // for turning OFF piezo after quick fault
    }


    /*
    CodeIn = getChar();
    switch(CodeIn) {
    case 'A':
    //Do something
    break;


    case 'W':
    //Do something
    break;


    case 'a':
    //Do something
    break;
    //etc etc etc
    }
    }
    */




    void LESSTHAN(){ // The first identifier was "<"
    //Do something (See void EQUALS)
    }




    void QUESTION(){ // The first identifier was "?"
    //Do something (See void EQUALS)
    }




    void SLASH(){ // The first identifier was "/" (Annunciators)
    CodeIn = getChar();
    AnunPinTot = 0; // for turning OFF piezo after quick fault
    for (count=0;count<7;count++) {
    if (CodeIn == AnunIdent2[count]){
    AnunPinValNew[count] = (getChar()- 4;
    if (AnunPinValNew[count] == 1){
    if (AnunPinValOld[count] < 1) {digitalWrite(AnunPinNo[count], HIGH);
    digitalWrite(piezo, HIGH);
    AnunPinValOld[count] = AnunPinValNew[count];}}
    if (AnunPinValNew[count] == 0){
    if (AnunPinValOld[count] > 0) {digitalWrite(AnunPinNo[count], LOW);AnunPinValOld[count] = AnunPinValNew[count];
    }}}
    if (AnunPinValOld[count] < 2 ){// for turning OFF piezo after quick fault
    AnunPinTot = (AnunPinTot + AnunPinValNew[count]);}
    //Serial.print(PinValNew[count]);
    }
    if (AnunPinTot < 1) {digitalWrite(piezo, LOW); } // for turning OFF piezo after quick fault
    }




    void ANNUNBUTTON(){
    counter = counter + 1;
    if (counter < 50000){counterTrigger = 0;}else {counterTrigger = 1;}
    if (counter > 100000) {counter = 1;}
    if (digitalRead(Anunbutton)==0){
    digitalWrite(piezo, LOW);
    for (count=0;count<7;count++) {
    if (AnunPinValOld[count] == 1){AnunPinValOld[count] = 3;}
    }
    }
    if (counterTrigger != counterTriggerOld) {
    for (count=0;count<7;count++) {
    if (AnunPinValOld[count] == 3) {
    if (counterTrigger == 1){digitalWrite(AnunPinNo[count], HIGH);}
    if (counterTrigger == 0){digitalWrite(AnunPinNo[count], LOW);}
    }
    }
    counterTriggerOld = counterTrigger;
    }
    }






    void PUSHTOTEST()
    {
    if (digitalRead(10)==0){
    if (bipassSwitchPins != 1){
    for (count=0; count<7;count++) {AnunPinNo[count] =13; }
    piezo = 13;
    for (count=2; count<9; count++) digitalWrite(count,HIGH);
    digitalWrite(11,HIGH);
    bipassSwitchPins = 1;
    }
    AnunButtonStop = millis() + 400;
    ButtonStopEnable = 1;
    }
    // cleanup
    if (((millis()) > AnunButtonStop) && ButtonStopEnable == 1){
    for (count=2; count<9; count++) {digitalWrite(count,LOW); }
    {digitalWrite(11,LOW); digitalWrite(13,LOW);}
    {AnunPinNo[0] = 2; AnunPinNo[1] = 3; AnunPinNo[2] = 4; AnunPinNo[3] = 5;}
    {AnunPinNo[4] = 6; AnunPinNo[5] = 7; AnunPinNo[6] = 8;}
    piezo= 11;
    for (count=0;count<7;count++) {
    if (AnunPinValOld[count] == 1) {digitalWrite(AnunPinNo[count],AnunPinValOld[count]); digitalWrite(piezo,HIGH);}
    {ButtonStopEnable = 0; bipassSwitchPins = 0;} // remove enable keys on exit
    }
    }
    }