Announcement

Collapse
No announcement yet.

Button not pressed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Button not pressed

    Hello,

    The i4dbutton seems not working. i dont see that SEROUT is transmitting.

    Thanks

    Code:
    ************************************************************************************************

    #platform "uLCD-32PTU"
    #inherit "ledDigitsDisplay.inc"

    #inherit "VisualConst.inc"

    #inherit "BagConst.inc"

    //#inherit "ledDigitsDisplay-ve.inc"

    #inherit "VisualConst.inc"

    //#inherit "spectrumConst.inc"

    func main()
    var numx, ch, numx1, ch1, numx2, ch2, e, e2, Loop;
    var combuf[10] ;
    var combuf1[10] ;
    var bar, frame;
    var i, x, y, state, n, Wbs1, Wbs3to5, WHITE, BLACK, FUCHSIA ;

    var sound := 0;
    e := 0;
    e2 := 0;

    //putstr("Mounting...\n");
    if (!(file_Mount()))
    while(!(file_Mount()))
    putstr("Drive not mounted...");
    pause(200);
    gfx_Cls();
    pause(200);
    wend
    endif
    hndl := file_LoadImageControl("Bag.dat", "Bag.gci", 1);
    Wbs1 := 0 ; // up, set to non zero (specifically 2) when down
    snd_BufSize(3);
    snd_Volume(127);
    file_PlayWAV("bl16k.wav");
    while(snd_Playing());

    //COM1_RX_pin(PA0);
    //COM2_RX_pin(PA1);

    gfx_Set(SCREEN_MODE,LANDSCAPE_R);
    txt_Set(TEXT_OPACITY, OPAQUE);
    com1_Init(combuf, 8, 0);
    com_Init(combuf1, 8, 0);
    com_SetBaud(COM1, 120); //9600 / 10
    com_SetBaud(COM0, 120); //9600 / 10

    //gfx_Set(CONTRAST,5) ;
    //txt_Set(TEXT_OPACITY, OPAQUE);

    //gfx_TransparentColour(0x0020);
    //gfx_Transparency(ON);


    // Label2 1.0 generated 04/11/2017 01:31:54
    //txt_FGcolour(WHITE) ;
    //txt_BGcolour(BLACK) ;

    //pin_Set(OUTPUT, AUDIO_ENABLE);
    pin_HI(AUDIO_ENABLE);

    // Winbutton1 generated 20/12/2011 3:55:28 PM
    // img_SetWord(hndl, iWinbutton1, IMAGE_FLAGS, (img_GetWord(hndl, iWinbutton1, IMAGE_FLAGS) | I_STAYONTOP) & ~I_TOUCH_DISABLE); // set to enable touch, only need to do this once

    //serout('Test') ; // SERIAL TEST
    // to(COM0); print("serial input test:\n");
    //trout('\n');OM1); print("serial input test:\n");

    /*
    img_ClearAttributes(hndl, i4Dbutton1, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
    img_SetWord(hndl, i4Dbutton1, IMAGE_INDEX, 0); // where state is 0 for up and 1 for down
    img_Show(hndl,i4Dbutton1) ;
    */


    touch_Set(TOUCH_ENABLE); // enable the touch screen



    // 4Dbutton1 1.0 generated 9/5/2020 8:34:24 PM
    img_ClearAttributes(hndl, i4Dbutton1, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
    img_Show(hndl, i4Dbutton1); // show button, only do this once
    img_SetWord(hndl, i4Dbutton1, IMAGE_INDEX, state); // where state is 0 for up and 1 for down
    img_Show(hndl,i4Dbutton1) ;


    img_Show(hndl, iLeddigits1); // show all digits at 0, only do this once
    //img_Show(hndl,iCoolgauge2) ;
    //img_Show(hndl,iCoolgauge1) ;

    // Image1 1.0 generated 9/4/2020 6:42:12 PM
    img_Show(hndl,iImage1) ; // LOGO
    pause(2000);
    gfx_Cls();

    // Image9 1.0 generated 9/5/2020 12:42:10 AM
    img_Show(hndl,iImage9) ;
    pause(2000);
    gfx_Cls();
    // Image10 1.0 generated 9/5/2020 12:42:45 AM
    img_Show(hndl,iImage10) ;
    pause(2000);
    gfx_Cls();

    repeat
    txt_FGcolour(WHITE) ;

    //sys_SetTimer(TIMER0, 2000); // set delay so we stay in next loop for 5 seconds
    //repeat
    // until (! sys_GetTimer(TIMER0)); // loop until TIME_OUT register is 0

    /* /////////
    if(com1_Count() > 1) // COM1 ==> Uart2/Yellow

    ch1 := (serin1() << 8 ) + serin1();
    endif
    state := touch_Get(TOUCH_STATUS); // get touchscreen status
    n := img_Touched(hndl,-1) ;

    ////////////////////////
    ///////////////////////

    //if (ch != -1)
    //gfx_MoveTo(0,0);
    //print( [CHR] ch ); // if a key was received from PC, print its ascii value

    numx1 := ch1; //RAND() % 999 ;

    // Leddigits1 1.0 generated 9/5/2020 12:40:30 AM
    img_Show(hndl, iLeddigits1); // show all digits at 0, only do this once
    ledDigitsDisplay(numx1, iLeddigits1+1, 124, 2, 1, 30, 0) ;
    *//////

    ///////////////////////
    ///////////////////////
    /*
    // now dump whatever we got to the terminal
    while ( (ch := serin()) >= 0)
    // txt_Set(TEXT_COLOUR, RED);
    gfx_MoveTo(0,0);
    // print("\n'",[CHR]char,"' is ");
    to(COM0); putch(ch); // send buffered chars to com port
    //wend
    */

    while ( (ch := serin()) >= 0)
    to(COM0); putch(ch); // send buffered chars to com port

    switch

    case (ch == 'm')


    // Image11 1.0 generated 9/5/2020 10:10:43 PM
    img_Show(hndl,iImage11) ;

    snd_BufSize(30);
    snd_Volume(sound);
    file_PlayWAV("beep.wav");

    pause(500);
    // gfx_Cls();

    case (ch == 'F')

    // Image3 1.0 generated 9/5/2020 7:47:04 PM
    img_Show(hndl,iImage3) ;
    img_Enable(hndl,iImage5) ;
    img_Show(hndl,iImage5) ;
    snd_BufSize(30);
    snd_Volume(sound);
    file_PlayWAV("beep.wav");

    pause(500);
    // gfx_Cls();

    case (ch == 'P')

    // Image2 1.0 generated 9/4/2020 9:21:48 PM
    img_Disable(hndl,iImage2) ;
    img_Enable(hndl,iImage6) ;
    img_Show(hndl,iImage6) ;
    snd_BufSize(30);
    snd_Volume(sound);
    file_PlayWAV("beep.wav");
    pause(500);
    // gfx_Cls();

    case (ch == 'B')

    // Image4 1.0 generated 9/4/2020 11:35:11 PM
    img_Disable(hndl,iImage4) ;
    img_Enable(hndl,iImage7) ;
    img_Show(hndl,iImage7) ;
    snd_BufSize(30);
    snd_Volume(sound);
    file_PlayWAV("beep.wav");
    pause(500);

    case (ch == 'f')

    // Image3 1.0 generated 9/4/2020 9:19:24 PM
    img_Disable(hndl,iImage5) ;

    // Image3 1.0 generated 9/5/2020 7:47:28 PM
    img_Enable(hndl,iImage3) ;

    img_Show(hndl,iImage3) ;
    snd_BufSize(30);
    snd_Volume(sound);
    file_PlayWAV("bleep1.wav");
    pause(500);
    // gfx_Cls();

    case (ch == 'p')

    // Image2 1.0 generated 9/4/2020 9:21:48 PM
    img_Disable(hndl,iImage6) ;
    img_Enable(hndl,iImage2) ;
    img_Show(hndl,iImage2) ;
    snd_BufSize(30);
    snd_Volume(sound);
    file_PlayWAV("bleep1.wav");
    pause(500);
    // gfx_Cls();

    case (ch == 'b')

    // Image4 1.0 generated 9/4/2020 11:35:11 PM
    img_Disable(hndl,iImage7) ;
    img_Enable(hndl,iImage4) ;
    img_Show(hndl,iImage4) ;
    snd_BufSize(30);
    snd_Volume(sound);
    file_PlayWAV("bleep1.wav");
    pause(500);

    default:

    endswitch

    //case (ch == 't')

    // Image8 1.0 generated 9/5/2020 7:40:09 PM
    img_Show(hndl,iImage8) ;

    // 4Dbutton1 1.0 generated 9/5/2020 8:34:24 PM
    img_ClearAttributes(hndl, i4Dbutton1, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
    img_Show(hndl, i4Dbutton1); // show button, only do this once
    img_SetWord(hndl, i4Dbutton1, IMAGE_INDEX, state); // where state is 0 for up and 1 for down
    img_Show(hndl,i4Dbutton1) ;

    if(com1_Count() > 1) // COM1 ==> Uart2/Yellow

    ch1 := (serin1() << 8 ) + serin1();
    endif
    state := touch_Get(TOUCH_STATUS); // get touchscreen status
    n := img_Touched(hndl,-1) ;

    ////////////////////////
    ///////////////////////

    //if (ch != -1)
    //gfx_MoveTo(0,0);
    //print( [CHR] ch ); // if a key was received from PC, print its ascii value

    numx1 := ch1; //RAND() % 999 ;

    // Leddigits1 1.0 generated 9/5/2020 12:40:30 AM
    img_Show(hndl, iLeddigits1); // show all digits at 0, only do this once
    ledDigitsDisplay(numx1, iLeddigits1+1, 124, 2, 1, 30, 0) ;
    // serout('T') ;
    //serout1('T') ;

    if(state == TOUCH_RELEASED) // if there's a release
    if (n == i4Dbutton1)
    if (Wbs1) Wbs1 := 0 ; else Wbs1 := 2 ; // toggle status
    img_SetWord(hndl, i4Dbutton1, IMAGE_INDEX, Wbs1); // where state is 0 for up, 1 for down, 2 for 'on' up and 3 for 'on' down
    img_Show(hndl,i4Dbutton1) ;
    print([DEC3ZB] 'a') ;
    // ASCII number written to the com port, or
    //serout(ch >> 8) ;
    serout1('r') ;
    snd_BufSize(30);
    snd_Volume(30);

    file_PlayWAV("bleep1.wav");
    while(snd_Playing());
    //com_Reset();
    //com1_Reset();

    endif
    //-----------------------------------------------------------------------------------------
    if(state == TOUCH_MOVING) // if it's moving
    x := touch_Get(TOUCH_GETX);
    y := touch_Get(TOUCH_GETY);
    endif

    state := touch_Get(TOUCH_STATUS); // get touchscreen status
    n := img_Touched(hndl,-1) ;

    //-----------------------------------------------------------------------------------------
    if(state == TOUCH_PRESSED) // if there's a press
    x := touch_Get(TOUCH_GETX);
    y := touch_Get(TOUCH_GETY);
    if (n == i4Dbutton1)
    img_SetWord(hndl, i4Dbutton1, IMAGE_INDEX, Wbs1+1); // where state is 0 for up, 1 for down, 2 for 'on' up and 3 for 'on' down
    img_Show(hndl,i4Dbutton1);
    print([DEC3ZB] 's') ;
    // ASCII number written to the com port, or
    //serout(ch >> 8) ;
    serout1('s') ;

    endif

    endif

    endif

    // gfx_Cls();
    // putstr(" THREE");
    // com_Init(combuffer, 2, 0); // reset buffer


    //txt_MoveCursor(3,1);
    //print("Buffered ", ( com1_Count() )); // show count of chars in buffer
    wend

    /*
    //-----------------------------------------------------------------------------------------
    if(state == TOUCH_RELEASED) // if there's a release
    if (n == i4Dbutton1)
    if (Wbs1) Wbs1 := 0 ; else Wbs1 := 2 ; // toggle status
    img_SetWord(hndl, i4Dbutton1, IMAGE_INDEX, Wbs1); // where state is 0 for up, 1 for down, 2 for 'on' up and 3 for 'on' down
    img_Show(hndl,i4Dbutton1) ;
    print([DEC3ZB] 'a') ;
    // ASCII number written to the com port, or
    //serout(ch >> 8) ;
    serout('a') ;
    snd_BufSize(30);
    snd_Volume(30);

    file_PlayWAV("bleep1.wav");
    while(snd_Playing());
    com_Reset();
    com1_Reset();

    endif

    if (n == i4Dbutton2)
    if (Wbs1) Wbs1 := 0 ; else Wbs1 := 2 ; // toggle status
    img_SetWord(hndl, i4Dbutton2, IMAGE_INDEX, Wbs1); // where state is 0 for up, 1 for down, 2 for 'on' up and 3 for 'on' down
    img_Show(hndl,i4Dbutton2) ;
    print([DEC3ZB] 'f') ;
    // ASCII number written to the com port, or
    //serout(ch >> 8) ;
    serout('f') ;
    snd_BufSize(30);
    snd_Volume(30);
    file_PlayWAV("beep.wav");
    //while(snd_Playing());
    endif

    //-----------------------------------------------------------------------------------------
    if(state == TOUCH_MOVING) // if it's moving
    x := touch_Get(TOUCH_GETX);
    y := touch_Get(TOUCH_GETY);
    endif

    state := touch_Get(TOUCH_STATUS); // get touchscreen status
    n := img_Touched(hndl,-1) ;

    //-----------------------------------------------------------------------------------------
    if(state == TOUCH_PRESSED) // if there's a press
    x := touch_Get(TOUCH_GETX);
    y := touch_Get(TOUCH_GETY);
    if (n == i4Dbutton1)
    img_SetWord(hndl, i4Dbutton1, IMAGE_INDEX, Wbs1+1); // where state is 0 for up, 1 for down, 2 for 'on' up and 3 for 'on' down
    img_Show(hndl,i4Dbutton1);
    print([DEC3ZB] 's') ;
    // ASCII number written to the com port, or
    //serout(ch >> 8) ;
    serout('s') ;

    endif

    endif

    endif
    */


    forever
    endfunc











  • #2
    Hi,

    Would you be able to Zip your project by clicking on File, Zip Project and then send the zip to me so I can do a test.

    The issue isn't immediately obvious and it would be easier to work with the complete project.

    Best regards

    Paul

    Comment

    Working...
    X