wiiconnect
Prev | Orchestra Opcodes and Operators | Next

## wiiconnect

wiiconnect — Reads data from a number of external Nintendo Wiimote controllers.

## Description

Opens and at control-rate polls up to four external Nintendo Wiimote controllers.

## Syntax

    ires wiiconnect [itimeout, imaxnum]

## Initialization

itimeout -- integer number of seconds the system should wait for all Wiimotes to be connected. If not given it defaults to 10 seconds.

imaxnum -- maximum number of Wiimotes to locate. If not given it defaults to 4.

Initially each Wiimote has its numeric allocation indicated by lighting one of the four LEDs.

ires -- return value is 1 if sucess or zero on failure.

## Performance

| Note
Please note that these opcodes are currently only supported on Linux.

Every control cycle each Wiimote is polled for its status and position. These values are read by the wiidata opcode. The result returned is 1 in most cases, but will be zero if a Wiimote disconnects,

## Example

Here is an example of the wii opcodes. It uses the file wii.csd.

Example 1081. Example of the wii opcodes.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>
    -+rtaudio=alsa -o dac:hw:0
    </CsOptions>
    <CsInstruments>
    nchnls = 2
    ksmps = 400

    #define WII_B           #3#
    #define WII_A           #4#
    #define WII_R_A         #304#
    #define WII_PITCH       #20#
    #define WII_ROLL        #21#
    #define WII_BATTERY     #27#

    #define WII_RUMBLE      #3#
    #define WII_SET_LEDS    #4#

    gkcnt init 1

    instr 1
      i1  wiiconnect 3,1

          wiirange   $WII_PITCH., -20, 0
      kb  wiidata    $WII_BATTERY.
      kt  wiidata    $WII_B.
      ka  wiidata    $WII_A.
      kra wiidata    $WII_R_A.
      gka wiidata    $WII_PITCH.
      gkp wiidata    $WII_ROLL.
    ; If the B (trigger) button is pressed then activate a note
      if  (kt==0)    goto ee
      event "i", 2, 0, 5
      gkcnt = gkcnt + 1
      wiisend       $WII_SET_LEDS., gkcnt
    ee:
      if (ka==0)    goto ff
      wiisend       $WII_RUMBLE., 1
    ff:
      if (kra==0)   goto gg
      wiisend       $WII_RUMBLE., 0
    gg:
      printk2  kb
    endin

    instr 2
      a1 oscil  ampdbfs(gka), 440+gkp, 1
         outs   a1, a1
    endin

    </CsInstruments>
    <CsScore>
    f1 0 4096 10 1
    i1 0 300

    </CsScore>
    </CsoundSynthesizer>

## See Also

wiidata, wiirange, wiisend

## Credits

Author: John ffitch
Codemist Ltd
2009

New in version 5.11

Prev | Up | Next
while | Home | wiidata