Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

-Use PLP branch instructions . Read from a memory mapped 1/O device The Task: Wr

ID: 3737420 • Letter: #

Question

-Use PLP branch instructions . Read from a memory mapped 1/O device The Task: Write a program in PLP assembly that repeatedly reads the value of the switches (address: exfe100000) and displays a pattern on the LED array based on what switches. Each time the switch value is read, the pattern should be displayed regardless of whether the switch value has changed or not since the last time it was read. The table below indicates the pattern that should be displayed for each possible switch setting: Switch Number 0 Hexadecimal Binary Switch Switch Value 0x00000001 b00000001 Turn all 8 LEDs on and then off 0x00000002 eb00000010 Turn all even numbered LEDs on and LED Pattern Value then off 0x00000004 b00000100 Turn all odd numbered LEDs on and then off 0x00000008 0b00001000 Cycle through all 8 LEDs in order with 2 only one LED on at a time (a marquee) Other Other Other All LEDs off Hint: Logical shifts are not required to complete this project, but they should make your program shorter and more readable than hard coding every value to be witten to the LEDs. Shifts can also be helpful when determining the switch value.

Explanation / Answer

This is used for fast Led Library

#include "FastLED.h"
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];
#define PIN 6

void setup()
{
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

// *** REPLACE FROM HERE ***
void loop() {
  // ---> here we call the effect function <---
}

// ---> here we define the effect function <---
// *** REPLACE TO HERE ***

void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
  }
showStrip();
}

// From here the code is for the Neo Pixel Framework

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 60
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}

// *** REPLACE FROM HERE ***
void loop() {
// ---> here we call the effect function <---
}

// ---> here we define the effect function <---
// *** REPLACE TO HERE ***

void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
  }
showStrip();
}

With this effect, we have used the fixed colors for all LEDs, in sequence color like: Red, Green and Blue.
We will increase brightness slowly and when the maximum brightness has been reached, we will start minimizing the brightness again until the LEDs are OFF.

Since the function is in the loop(), it will keep repeating itself.

void loop() {
RGBLoop();
}

void RGBLoop(){
  for(int j = 0; j < 3; j++ ) {
  // Fade IN
  for(int k = 0; k < 256; k++) {
  switch(j) {
  case 0: setAll(k,0,0); break;
  case 1: setAll(0,k,0); break;
  case 2: setAll(0,0,k); break;
  }
showStrip();
delay(3);
  }
  // Fade OUT
  for(int k = 255; k >= 0; k--) {
  switch(j) {
  case 0: setAll(k,0,0); break;
  case 1: setAll(0,k,0); break;
  case 2: setAll(0,0,k); break;
  }
showStrip();
delay(3);
  }
  }
}

Now fading in and out only red, green and blue is nice, but what about fade in and out your own color?

If you’re not sure how to determine your own color, check out the previously mentioned Color Picker.

//FADE IN AND FADE OUT YOUR QWN COLOR

void loop() {
FadeInOut(0xff, 0x00, 0x00); // red
FadeInOut(0xff, 0xff, 0xff); // white
FadeInOut(0x00, 0x00, 0xff); // blue
}

//THE EFFECT CODE

void loop() {
FadeInOut(0xff, 0x77, 0x00);
}

void FadeInOut(byte red, byte green, byte blue){
  float r, g, b;
  
  for(int k = 0; k < 256; k=k+1) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);
showStrip();
  }

  for(int k = 255; k >= 0; k=k-2) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);
showStrip();
  }
}

void loop() {
FadeInOut(0xff, 0x77, 0x00);
}

void FadeInOut(byte red, byte green, byte blue){
  float r, g, b;
  
  for(int k = 0; k < 256; k=k+1) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);
showStrip();
  }

  for(int k = 255; k >= 0; k=k-2) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);
showStrip();
  }
}