#include <SimpleRotary.h>
#include <Mouse.h>
int led = 10;           // the PWM pin the LED is attached to
byte brightness = 0;
// soldered my scrollwheel to pins 6 and 7. so fill in the pins that you connected your scrollwheel to. if you have a button asw fill // in the pin you connected that to in the last field, but since I have no middle mouse click connected I left it at 0.
SimpleRotary rotary(6, 7, 0);


void setup() {
  // startup the mouse code
  pinMode(led, OUTPUT);
  //Mouse.begin();
void loop() {
  // put your main code here, to run repeatedly:
}

  byte i;
  i = rotary.rotate();
  analogWrite(led, brightness);


  if ( i == 0) {
    //Serial.print("not scrolling");
    aftellen();
  }

  // CW rotation
  if ( i == 1 ) {
    brightness++;
    Serial.println(brightness);
    // if you want to check if your scrollwheel works you can fill in the following code: (otherwise you can just delete it to clean things up)
    //Serial.print("CCW");
    //Serial.print("\t");
    //Serial.println(i);
     //Mouse.move() let's us either move the x/y-axis or the mouse wheel (which is the third one). in this code if the i is the same as 1 
     // it'll tell the virtual mouse to scroll up 1 whatever they use to measure this.
    Mouse.move(0,0,1);
    // turns clockwise
  }

  // CCW rotation
  if ( i == 2 ) {
    brightness++;
    Serial.println(brightness);
    // if you want to check if your scrollwheel works you can fill in the following code: (otherwise you can just delete it to clean things up)
    //Serial.print("CCW");
    //Serial.print("\t");
    //Serial.println(i);
    // exact same as before but the other way around
   Mouse.move(0,0,-1);
    // turns counter clock wise
  }

}

void aftellen()
{
  static const unsigned long REFRESH_INTERVAL = 100; // ms
  static unsigned long lastRefreshTime = 0;

  if (millis() - lastRefreshTime >= REFRESH_INTERVAL)
  {
    lastRefreshTime += REFRESH_INTERVAL;
    if (brightness > 0) {
      brightness--;
      Serial.println(brightness);
    }
  }
}
