Mindstorms 3rd Party ROBOTC Drivers RobotC
[Home] [Download] [Submit a bug/suggestion] [ROBOTC Forums] [Blog] [Support this project]

mindsensors-touchpanel-test1.c

#pragma config(Sensor, S3,     MSTP,                sensorI2CCustom)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*
 * $Id: mindsensors-touchpanel-test1.c 133 2013-03-10 15:15:38Z xander $
 */

/**
 * mindsensors-touchpanel.h provides an API for the Mindsensors TouchPanel. This program
 * demonstrates how to use that API.
 *
 * Changelog:
 * - 0.1: Initial release
 *
 * Credits:
 * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
 *
 * License: You may use this code as you wish, provided you give credit where it's due.
 *
 * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. 

 * Xander Soldaat (xander_at_botbench.com)
 * 30 November 2011
 * version 0.1
 */


#include "drivers/mindsensors-touchpanel.h"


task main () {
  nxtDisplayCenteredTextLine(0, "MindSensors");
  nxtDisplayCenteredBigTextLine(1, "TouchPnl");
  nxtDisplayCenteredTextLine(3, "Noise-a-Tron");
  nxtDisplayCenteredTextLine(5, "Connect sensor");
  nxtDisplayCenteredTextLine(6, "to S3");
  wait1Msec(2000);
  eraseDisplay();

  int x, y = 0;
  ubyte buttons = 0;
  int multiplierX = 10;
  int multiplierY = 10;
  while (true) {
    if (!MSTPgetTouch(MSTP, x, y, buttons))
      PlaySound(soundBlip);
    else if (isButtonTouched(buttons, BUTTON_L1))
      multiplierX = 10;
    else if (isButtonTouched(buttons, BUTTON_L2))
      multiplierX = 15;
    else if (isButtonTouched(buttons, BUTTON_L3))
      multiplierX = 20;
    else if (isButtonTouched(buttons, BUTTON_L4))
      multiplierX = 25;
    else if (isButtonTouched(buttons, BUTTON_R1))
      multiplierY = 10;
    else if (isButtonTouched(buttons, BUTTON_R2))
      multiplierY = 15;
    else if (isButtonTouched(buttons, BUTTON_R3))
      multiplierY = 20;
    else if (isButtonTouched(buttons, BUTTON_R4))
      multiplierY = 25;

    else if (x > 0 && y > 0)
    {
      PlayImmediateTone(x * multiplierX, 1);
      wait1Msec(10);
      PlayImmediateTone(y * multiplierY, 1);
      nxtSetPixel(x, y);
    }
    EndTimeSlice();
  }
}