M4_Eyes/user_wiichuck.cpp
void user_loop(void) {
  nunchuck1.readData();    // Read inputs and update maps
  
  int joyX = nunchuck1.getJoyX();
  int joyY = nunchuck1.getJoyY();
//  Serial.println("joyXY(" + String(joyX) + ", " + String(joyY) + ")");
  float x = map2(joyX, low, high, -1.0, 1.0);
  float y = map2(joyY, low, high, -1.0, 1.0);
  int cornerX = (joyX - low) / divFactor;
  int cornerY = (joyY - low) / divFactor;
  int chaseColor = 0;
  if(cornerX == 1 && cornerY == 1) { // return to normal when the joystick is in the middle
    eyesNormal();
    neoPixelState = LUMINESCENT;
  } else {
    eyesToCorner(x, -y, true);
    if(cornerX < 1) {
      chaseColor = green;
      neoPixelState = CHASE_LEFT;
    } else if(cornerX > 1) {
      chaseColor = blue;
      neoPixelState = CHASE_RIGHT;
    } else if(cornerY > 1) {
      neoPixelState = CHASE_UP;
      chaseColor = green;
    } else if(cornerY < 1) {
      neoPixelState = CHASE_DOWN;
      chaseColor = blue;
    }
  }
  
  bool buttonC = nunchuck1.getButtonC();
  bool buttonZ = nunchuck1.getButtonZ();

  if(buttonC && buttonZ) {
    Serial.println("buttonC & buttonZ");
    chaseColor = red;
    if(neoPixelState == LUMINESCENT)
      neoPixelState = CHASE_UP;
  } else {
    if(buttonC) {
      Serial.println("buttonC");
      eyesWide();
      neoPixelState = SPARKLE;
    } else if(buttonZ) {
      Serial.println("buttonZ");
      eyesClose();
    }
  }

  if(strip.numPixels() > 0) {
    // Serial.println("neo state=" + String(neoPixelState));
    switch (neoPixelState) {
      case LUMINESCENT: neoShine(); break;
      case CHASE_RIGHT: neoChase(4, 3, chaseColor); break;
      case CHASE_LEFT: neoChase(2, 3,  chaseColor); break;
      case CHASE_UP: neoUpDown(chaseColor, 1); break;
      case CHASE_DOWN: neoUpDown(chaseColor, -1); break;
      case SPARKLE: neoSparkle(); break;
    }
  }
}
// Called periodically during eye animation. This is invoked in the
// interval before starting drawing on the last eye (left eye on MONSTER
// M4SK, sole eye on HalloWing M0) so it won't exacerbate visible tearing
// in eye rendering. This is also SPI "quiet time" on the MONSTER M4SK so
// it's OK to do I2C or other communication across the bridge.
// This function BLOCKS, it does NOT multitask with the eye animation code,
// and performance here will have a direct impact on overall refresh rates,
// so keep it simple. Avoid loops (e.g. if animating something like a servo
// or NeoPixels in response to some trigger) and instead rely on state
// machines or similar. Additionally, calls to this function are NOT time-
// constant -- eye rendering time can vary frame to frame, so animation or
// other over-time operations won't look very good using simple +/-
// increments, it's better to use millis() or micros() and work
// algebraically with elapsed times instead.
Called periodically during eye animation. This is invoked in the
interval before starting drawing on the last eye (left eye on MONSTER
M4SK, sole eye on HalloWing M0) so it won't exacerbate visible tearing
in eye rendering. This is also SPI "quiet time" on the MONSTER M4SK so
it's OK to do I2C or other communication across the bridge.
This function BLOCKS, it does NOT multitask with the eye animation code,
and performance here will have a direct impact on overall refresh rates,
so keep it simple. Avoid loops  and instead rely on state
machines or similar. Additionally, calls to this function are NOT time
constant -- eye rendering time can vary frame to frame, so animation or
other over-time operations won't look very good using simple +
increments, it's better to use millis() or micros() and work
algebraically with elapsed times instead.
Called periodically during eye animation . This is invoked in the interval before starting drawing on the last eye ( left eye on MONSTER M4SK sole eye on HalloWing M0 ) so it won ' t exacerbate visible tearing in eye rendering . This is also SPI " quiet time " on the MONSTER M4SK so it ' s OK to do I2C or other communication across the bridge . This function BLOCKS it does NOT multitask with the eye animation code and performance here will have a direct impact on overall refresh rates so keep it simple . Avoid loops and instead rely on state machines or similar . Additionally calls to this function are NOT time constant -- eye rendering time can vary frame to frame so animation or other over - time operations won ' t look very good using simple + increments it ' s better to use millis () or micros () and work algebraically with elapsed times instead .
void user_loop(void) {
  nunchuck1.readData();    
  int joyX = nunchuck1.getJoyX();
  int joyY = nunchuck1.getJoyY();
  float x = map2(joyX, low, high, -1.0, 1.0);
  float y = map2(joyY, low, high, -1.0, 1.0);
  int cornerX = (joyX - low) / divFactor;
  int cornerY = (joyY - low) / divFactor;
  int chaseColor = 0;
  if(cornerX == 1 && cornerY == 1) { 
    eyesNormal();
    neoPixelState = LUMINESCENT;
  } else {
    eyesToCorner(x, -y, true);
    if(cornerX < 1) {
      chaseColor = green;
      neoPixelState = CHASE_LEFT;
    } else if(cornerX > 1) {
      chaseColor = blue;
      neoPixelState = CHASE_RIGHT;
    } else if(cornerY > 1) {
      neoPixelState = CHASE_UP;
      chaseColor = green;
    } else if(cornerY < 1) {
      neoPixelState = CHASE_DOWN;
      chaseColor = blue;
    }
  }
  bool buttonC = nunchuck1.getButtonC();
  bool buttonZ = nunchuck1.getButtonZ();
  if(buttonC && buttonZ) {
    Serial.println("buttonC & buttonZ");
    chaseColor = red;
    if(neoPixelState == LUMINESCENT)
      neoPixelState = CHASE_UP;
  } else {
    if(buttonC) {
      Serial.println("buttonC");
      eyesWide();
      neoPixelState = SPARKLE;
    } else if(buttonZ) {
      Serial.println("buttonZ");
      eyesClose();
    }
  }
  if(strip.numPixels() > 0) {
    switch (neoPixelState) {
      case LUMINESCENT: neoShine(); break;
      case CHASE_RIGHT: neoChase(4, 3, chaseColor); break;
      case CHASE_LEFT: neoChase(2, 3,  chaseColor); break;
      case CHASE_UP: neoUpDown(chaseColor, 1); break;
      case CHASE_DOWN: neoUpDown(chaseColor, -1); break;
      case SPARKLE: neoSparkle(); break;
    }
  }
}
void user_loop ( void ) { nunchuck1 . readData ( ) ; int joyX = nunchuck1 . getJoyX ( ) ; int joyY = nunchuck1 . getJoyY ( ) ; float x = map2 ( joyX , low , high , -1.0 , 1.0 ) ; float y = map2 ( joyY , low , high , -1.0 , 1.0 ) ; int cornerX = ( joyX - low ) / divFactor ; int cornerY = ( joyY - low ) / divFactor ; int chaseColor = 0 ; if ( cornerX == 1 && cornerY == 1 ) { eyesNormal ( ) ; neoPixelState = LUMINESCENT ; } else { eyesToCorner ( x , - y , true ) ; if ( cornerX < 1 ) { chaseColor = green ; neoPixelState = CHASE_LEFT ; } else if ( cornerX > 1 ) { chaseColor = blue ; neoPixelState = CHASE_RIGHT ; } else if ( cornerY > 1 ) { neoPixelState = CHASE_UP ; chaseColor = green ; } else if ( cornerY < 1 ) { neoPixelState = CHASE_DOWN ; chaseColor = blue ; } } bool buttonC = nunchuck1 . getButtonC ( ) ; bool buttonZ = nunchuck1 . getButtonZ ( ) ; if ( buttonC && buttonZ ) { Serial . println ( " " ) ; chaseColor = red ; if ( neoPixelState == LUMINESCENT ) neoPixelState = CHASE_UP ; } else { if ( buttonC ) { Serial . println ( " " ) ; eyesWide ( ) ; neoPixelState = SPARKLE ; } else if ( buttonZ ) { Serial . println ( " " ) ; eyesClose ( ) ; } } if ( strip . numPixels ( ) > 0 ) { switch ( neoPixelState ) { case LUMINESCENT : neoShine ( ) ; break ; case CHASE_RIGHT : neoChase ( 4 , 3 , chaseColor ) ; break ; case CHASE_LEFT : neoChase ( 2 , 3 , chaseColor ) ; break ; case CHASE_UP : neoUpDown ( chaseColor , 1 ) ; break ; case CHASE_DOWN : neoUpDown ( chaseColor , -1 ) ; break ; case SPARKLE : neoSparkle ( ) ; break ; } } }
Called periodically during eye animation.
Called periodically during eye animation .
// Read inputs and update maps //  Serial.println("joyXY(" + String(joyX) + ", " + String(joyY) + ")"); // return to normal when the joystick is in the middle // Serial.println("neo state=" + String(neoPixelState));