Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Hopefully simple coding solution

  1. #1

    Hopefully simple coding solution

    I am a sys admin who inherited this project and could use a helping hand. This is a simple LCD running on a Teensy 2.0 board and has two push to talk buttons.

    I know nothing about programming but managed to pull the RGB colors off of the hardware and am now able to manipulate them in code.

    The only thing I need to do now is make the lcd blink another color when the button is pushed. so right now say its blue they hit the button and I want it to turn green just for a second to acknowledge the button was pushed. and that's it lol

    Any help or guidance is immensely appreciated and I will owe you beer if you help me.
    here is my code!

    #include <Bounce.h>
    #include <LiquidCrystal.h>

    Bounce ptt0 = Bounce(14, 10);
    Bounce chanSelect0 = Bounce(13, 10);
    LiquidCrystal lcd(12, 11, 23, 22, 8, 7);

    int redpin = 4;
    int greenpin = 9;
    int bluepin = 10;

    int pttPressed = 0;
    int chanPressed = 0;
    int chanNum = 1;

    void setup() {
    pinMode (redpin, OUTPUT) ;
    pinMode (greenpin, OUTPUT) ;
    pinMode (bluepin, OUTPUT) ;

    pinMode(14, INPUT_PULLUP);
    pinMode(13, INPUT_PULLUP);
    lcd.begin(16, 2);
    lcd.print("Ch 1 - P!");
    lcd.setCursor(0, 1);
    lcd.print("----------------");
    digitalWrite (greenpin, HIGH) ;
    }

    void loop() {
    ptt0.update();
    chanSelect0.update();


    if (ptt0.fallingEdge() && chanPressed == 0) {
    pttPressed = 1;

    Keyboard.set_modifier(MODIFIERKEY_SHIFT);
    Keyboard.set_key1(KEY_P);

    //If the channel == 1 then send P!
    if (chanNum == 1) {
    Keyboard.set_key2(KEY_1);
    }
    //If the channel == 2 then send P@
    if (chanNum == 2) {
    Keyboard.set_key2(KEY_2);
    }
    //If the channel == 3 then send P#
    if (chanNum == 3) {
    Keyboard.set_key2(KEY_3);
    }
    //If the channel == 1 then send P$
    if (chanNum == 4) {
    Keyboard.set_key2(KEY_4);
    }
    //If the channel == 5 then send P%
    if (chanNum == 5) {
    Keyboard.set_key2(KEY_5);
    }
    lcd.setCursor(0, 1);
    lcd.print("....Transmit....");

    Keyboard.send_now();
    }

    if (ptt0.risingEdge() && pttPressed == 1) {
    pttPressed = 0;
    Keyboard.set_modifier(0);
    Keyboard.set_key1(0);
    Keyboard.set_key2(0);
    lcd.setCursor(0, 1);
    lcd.print("----------------");
    Keyboard.send_now();
    }

    if (chanSelect0.fallingEdge() && pttPressed == 0) {
    chanPressed = 1;
    }

    if (chanSelect0.risingEdge() && pttPressed == 0) {
    if (chanNum == 5) {
    chanNum = 1;
    lcd.setCursor(0, 0);
    lcd.print("Ch 1 - P!");
    } else {
    chanNum = chanNum + 1;
    if (chanNum == 2) {
    lcd.setCursor(0, 0);
    lcd.print("Ch 2 - P@");
    }
    if (chanNum == 3) {
    lcd.setCursor(0, 0);
    lcd.print("Ch 3 - P#");
    }
    if (chanNum == 4) {
    lcd.setCursor(0, 0);
    lcd.print("Ch 4 - P$");
    }
    }
    chanPressed = 0;
    }
    }

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Location
    Chipping Norton, UK
    Posts
    278
    From the code, knowing nothing about the hardware you are using, the last line of the setup method implies that the display IS green:

    digitalWrite (greenpin, HIGH) ;

    to turn it blue, pause 1 second, then back to green for example I would guess:

    digitalWrite (greenpin, LOW) ;
    digitalWrite (redpin, LOW) ;
    digitalWrite (bluepin, HIGH) ;
    delay(1000);
    digitalWrite (greenpin, HIGH) ;
    digitalWrite (bluepin, LOW) ;

    For the PTT button, replace:
    if (ptt0.risingEdge() && pttPressed == 1) {
    pttPressed = 0;
    Keyboard.set_modifier(0);
    Keyboard.set_key1(0);
    Keyboard.set_key2(0);
    lcd.setCursor(0, 1);
    lcd.print("----------------");
    Keyboard.send_now();
    }
    With:

    if (ptt0.risingEdge() && pttPressed == 1) {
    pttPressed = 0;
    Keyboard.set_modifier(0);
    Keyboard.set_key1(0);
    Keyboard.set_key2(0);
    lcd.setCursor(0, 1);
    lcd.print("----------------");
    Keyboard.send_now();
    digitalWrite (greenpin, LOW) ;
    digitalWrite (redpin, LOW) ;
    digitalWrite (bluepin, HIGH) ;
    delay(1000);
    digitalWrite (greenpin, HIGH) ;
    digitalWrite (bluepin, LOW) ;
    }

  3. #3
    Senior Member
    Join Date
    Nov 2012
    Location
    Chipping Norton, UK
    Posts
    278
    I guess if it is blue normally the pins are misnamed

  4. #4
    Thank you so much, I really appreciate the information. Hopefully that will do it!
    As far as hardware its just a 20x4 lcd
    teensy 2.0
    2 push to talk buttons
    1 button will key the radio for our pilots
    1 button will manipulate keyboard short cuts to change radio channels.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,996
    I want it to turn green just for a second to acknowledge the button was pushed. and that's it lol
    You probably want to add an elapsedMillis variable for this. In the code that responds to the button, set the LED to green and set the variable to zero.

    Elsewhere in the loop, check if the variable is greater than 1000 (more than 1 second since it was set to zero). If so, turn off the green and turn on the blue.

    Create the elapsedMillis variable outside loop(), so it retains it value and keep incrementing.

  6. #6
    Thank you for the response Paul. I think I follow what your saying but putting that into code is going to be the real challenge LOL. I am not a programmer in any sense of the word and have definitely found a new respect for those of you who do. Thanks for all of the advice folks. hopefully I can take this info and turn it into something useful.

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,996
    Anything is impossible as long as you keep convincing yourself it is.

    I and others here can try to help you, but first you have to want to really give it a try.

  8. #8
    Senior Member
    Join Date
    Nov 2012
    Location
    Chipping Norton, UK
    Posts
    278
    Good call Paul, I didn't really get the application, a 1 second delay in the loop would most likely have had an unwanted effect at some point

  9. #9
    Thanks again you two. I studied the info you gave me and it put me in a spot where I could make an educated guess on the code and placement. This morning I will be presenting my demo to the military and they should be very happy. You guys saved me alot of grief. Yall are awesome!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •