Code for PanType by Christine Gregg

Dependencies:   DebounceIn USBDevice mbed

Fork of Text_input_alt by Interactive Device Design

main.cpp

Committer:
figlax
Date:
2014-09-22
Revision:
0:8e978e353ded

File content as of revision 0:8e978e353ded:

#include "mbed.h"
#include "DebounceIn.h"
//must import cookbook debounce library into project

DigitalOut myled(LED3);

DigitalOut myled2(LED1);

DigitalOut myled3(LED2);

Serial pc(USBTX, USBRX); // tx, rx
DebounceIn button(D3);
DebounceIn button2(D4);
DebounceIn button3(D5);
DebounceIn button4(D6);
DebounceIn button5(D7);
DebounceIn button6(D8);
DebounceIn button7(D9);
DebounceIn button8(D10);
DebounceIn toggle(D2);
DebounceIn enter(D11);


int main()
{

    //initiate button modes to use internal pull up resistor
    button.mode(PullUp);
    button2.mode(PullUp);
    button3.mode(PullUp);
    button4.mode(PullUp);
    button5.mode(PullUp);
    button6.mode(PullUp);
    button7.mode(PullUp);
    button8.mode(PullUp);
    toggle.mode(PullUp);
    enter.mode(PullUp);

    wait(0.001);

    //initiate counters and other variables

    int enter_old=1;
    int enter_new;
    int toggle_old=1;
    int toggle_new;
    int button_old=1;
    int button_new;
    int button2_old=1;
    int button2_new;
    int button3_old=1;
    int button3_new;
    int button4_old=1;
    int button4_new;
    int button5_old=1;
    int button5_new;
    int button6_old=1;
    int button6_new;
    int button7_old=1;
    int button7_new;
    int button8_old=1;
    int button8_new;

    int b1=0;
    int b2=0;
    int b3=0;
    int b4=0;
    int b5=0;
    int b6=0;
    int b7=0;
    int b8=0;

    int button_counter=0;
    int button2_counter=0;
    int button3_counter=0;
    int button4_counter=0;
    int button5_counter=0;
    int button6_counter=0;
    int button7_counter=0;
    int button8_counter=0;




    int l=3;
    int l2=3;
    int l3=3;
    int l4=3;
    int l5=3;
    int l6=3;
    int l7=4;
    int l8=4;


    char* s[26] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};

    myled=1;
    myled3=1;

    myled2=0;
    wait(0.4);
    myled2=1;
    wait(0.4);
    myled2=0;
    wait(0.4);
    myled2=1;
    wait(0.4);
    myled2=0;
    wait(0.4);
    myled2=1;
    wait(0.4);

    myled=0;
    wait(0.4);
    myled=1;


//start main program

    while(1) {
        enter_new = enter.read();
        if((enter_new==0) && (enter_old==1)) {
            myled3= 0;
            wait(0.2);
            myled3= 1;

            if (b1>0) {
                button_counter= button_counter - 1;
                pc.printf("%s", s[button_counter]);
                button_counter=0;

            }
            if (b2>0) {
                button2_counter= button2_counter + l - 1;
                pc.printf("%s", s[button2_counter]);
                button2_counter=0;

            }
            if (b3>0) {
                button3_counter= button3_counter + l + l2 - 1;
                pc.printf("%s", s[button3_counter]);
                button3_counter=0;

            }
            if (b4>0) {
                button4_counter= button4_counter  + l + l2 + l3 - 1;
                pc.printf("%s", s[button4_counter]);
                button4_counter=0;

            }
            if (b5>0) {
                button5_counter= button5_counter  + l + l2 + l3 + l4 - 1;
                pc.printf("%s", s[button5_counter]);
                button5_counter=0;

            }
            if (b6>0) {
                button6_counter= button6_counter  + l + l2 + l3 + l4 + l5 - 1;
                pc.printf("%s", s[button6_counter]);
                button6_counter=0;

            }
            if (b7>0) {
                button7_counter= button7_counter  + l + l2 + l3 + l4 + l5 +l6 - 1;
                pc.printf("%s", s[button7_counter]);
                button7_counter=0;

            }
            if (b8>0) {
                button8_counter= button8_counter  + l + l2 + l3 + l4 + l5 +l6 + l7 - 1;
                pc.printf("%s", s[button8_counter]);
                button8_counter=0;

            }
            button_counter=0;
            button2_counter=0;
            button3_counter=0;
            button4_counter=0;
            button5_counter=0;
            button6_counter=0;
            button7_counter=0;
            button8_counter=0;

            b1=0;
            b2=0;
            b3=0;
            b4=0;
            b5=0;
            b6=0;
            b7=0;
            b8=0;
        }
        enter_old= enter_new;


        toggle_new = toggle.read();
        if ((toggle_new==0) && (toggle_old==1)) {


            pc.printf(" ");
        }
        toggle_old= toggle_new;

        button_new=button.read();
        if ((button_old==0)&&(button_new==1)) {
            myled= 0;
            wait(0.2);
            myled= 1;

            b1=1;
            b2=0;
            b3=0;
            b4=0;
            b5=0;
            b6=0;
            b7=0;
            b8=0;

            button_counter= button_counter + 1;
            button2_counter=0;
            button3_counter=0;
            button4_counter=0;
            button5_counter=0;
            button6_counter=0;
            button7_counter=0;
            button8_counter=0;
            if (button_counter==(l + 1)) {
                button_counter=1;
            }

        }
        button_old=button_new;

        button2_new=button2.read();
        if ((button2_old==0)&&(button2_new==1)) {
            myled= 0;
            wait(0.2);
            myled= 1;
            b1=0;
            b2=1;
            b3=0;
            b4=0;
            b5=0;
            b6=0;
            b7=0;
            b8=0;
            button_counter= 0;
            button2_counter= button2_counter + 1;
            button3_counter=0;
            button4_counter=0;
            button5_counter=0;
            button6_counter=0;
            button7_counter=0;
            button8_counter=0;
            if (button2_counter==(l2 + 1)) {
                button2_counter=1;
            }

        }
        button2_old=button2_new;


        button3_new=button3.read();
        if ((button3_old==0)&&(button3_new==1)) {
            myled= 0;
            wait(0.2);
            myled= 1;
            b1=0;
            b2=0;
            b3=1;
            b4=0;
            b5=0;
            b6=0;
            b7=0;
            b8=0;
            button_counter= 0;
            button2_counter=0;
            button3_counter= button3_counter + 1;
            button4_counter=0;
            button5_counter=0;
            button6_counter=0;
            button7_counter=0;
            button8_counter=0;
            if (button3_counter==(l3 + 1)) {
                button3_counter=1;
            }

        }
        button3_old=button3_new;

        button4_new=button4.read();
        if ((button4_old==0)&&(button4_new==1)) {
            myled= 0;
            wait(0.2);
            myled= 1;
            b1=0;
            b2=0;
            b3=0;
            b4=1;
            b5=0;
            b6=0;
            b7=0;
            b8=0;
            button_counter= 0;
            button2_counter=0;
            button3_counter=0;
            button4_counter= button4_counter + 1;
            button5_counter=0;
            button6_counter=0;
            button7_counter=0;
            button8_counter=0;
            if (button4_counter==(l4 + 1)) {
                button4_counter=1;
            }

        }
        button4_old=button4_new;

        button5_new=button5.read();
        if ((button5_old==0)&&(button5_new==1)) {
            myled= 0;
            wait(0.2);
            myled= 1;
            b1=0;
            b2=0;
            b3=0;
            b4=0;
            b5=1;
            b6=0;
            b7=0;
            b8=0;
            button_counter=0;
            button2_counter=0;
            button3_counter=0;
            button4_counter=0;
            button5_counter= button5_counter + 1;
            button6_counter=0;
            button7_counter=0;
            button8_counter=0;
            if (button5_counter==(l5 + 1)) {
                button5_counter=1;
            }

        }
        button5_old=button5_new;


        button6_new=button6.read();
        if ((button6_old==0)&&(button6_new==1)) {
            myled= 0;
            wait(0.2);
            myled= 1;
            b1=0;
            b2=0;
            b3=0;
            b4=0;
            b5=0;
            b6=1;
            b7=0;
            b8=0;
            button_counter= 0;
            button2_counter=0;
            button3_counter=0;
            button4_counter=0;
            button5_counter=0;
            button6_counter= button6_counter + 1;
            button7_counter=0;
            button8_counter=0;
            if (button6_counter==(l6 + 1)) {
                button6_counter=1;
            }

        }
        button6_old=button6_new;


        button7_new=button7.read();
        if ((button7_old==0)&&(button7_new==1)) {
            myled= 0;
            wait(0.2);
            myled= 1;
            b1=0;
            b2=0;
            b3=0;
            b4=0;
            b5=0;
            b6=0;
            b7=1;
            b8=0;
            button_counter= 0;
            button2_counter=0;
            button3_counter=0;
            button4_counter=0;
            button5_counter=0;
            button6_counter=0;
            button7_counter= button7_counter + 1;
            button8_counter=0;
            if (button7_counter==(l7 + 1)) {
                button7_counter=1;
            }

        }
        button7_old=button7_new;

        button8_new=button8.read();
        if ((button8_old==0)&&(button8_new==1)) {
            myled= 0;
            wait(0.2);
            myled= 1;
            b1=0;
            b2=0;
            b3=0;
            b4=0;
            b5=0;
            b6=0;
            b7=0;
            b8=1;
            button_counter= 0;
            button2_counter=0;
            button3_counter=0;
            button4_counter=0;
            button5_counter=0;
            button6_counter=0;
            button7_counter=0;
            button8_counter=button8_counter + 1;
            if (button8_counter==(l8 + 1)) {
                button8_counter=1;
            }

        }
        button8_old=button8_new;









    }
}