ROBOT MAGIC

CHAPTER Eleven: Pepper's Ghost in a Cereal Box

Make_RobotMagic_Cover_01jb.jpg

Copy + Paste this code to your Arduino Sketch:

Watercolor Stain

#include <Button.h>

 

Button button = Button(5,PULLDOWN);

 

int ledPin = 11;

int ledPin2 = 10;

 

void setup(){

  

  pinMode(ledPin, OUTPUT);

  pinMode(ledPin2, OUTPUT);

 

  digitalWrite(ledPin, HIGH);

 

}

 

byte pressCount = 0;

 

void loop(){

 

static int fadeValue = 0;

static int fadeValue2 = 255;

 

if (button.uniquePress())

pressCount++;

 

switch(pressCount)

 

{

  

case 1:

 

   if (fadeValue < 255)

   {

    fadeValue++;

    fadeValue2--;

     analogWrite(ledPin2, fadeValue);

     analogWrite(ledPin, fadeValue2);

     delay(55);

   }

  

break;

 

case 2:

 

  if (fadeValue2 < 255) {

    fadeValue--;

    fadeValue2++;

     analogWrite(ledPin2, fadeValue);

     analogWrite(ledPin, fadeValue2);

     delay(55);

 

  }

 

break;

 

default:

 

pressCount = 0;

 

break;

  }

}

Show us your finished projects! Use #robotmagic in your social media posts and tag Mario!

  • Facebook
  • Instagram
  • Twitter
  • YouTube
  • TikTok