Question

C language. A file, display.c handles all display to the LED array. It will need a...

C language. A file, display.c handles all display to the LED array. It will need a global variable with type *pi_framebuffer_t. (in C, "global" variables are scoped only to the file in which they are defined unless other actions are taken). Should have at least the following functions:
void openDisplay(void): allocate the Pi Framebuffer device and store in a "global" variable for later use. This function should only need to be called one time when the program runs.
void closeDisplay(void): deallocate the Pi Framebuffer device (if it exists) and set the storage variable to NULL. Be sure this does the right thing if called before openDisplay()!
void displayLetter(char letter, int xOffset, int yOffset) : draws the provided letter on the LED array oriented so that "down" is towards the joystick, but shifted to the right by xOffset and down by yOffset. Note: the only letters you need to be able to draw are the capital initials of all partners in your group (you should be able to draw upon the "monogramming" assignment). Don't forget that if all letters would be the same, substitute a '3' for one of them.
void clearDisplay(void): clears the display

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include "scroll.h"
#include <stddef.h>
#include <stdio.h>
#include "sense.h"

#define BLACK 0x0000
#define WHITE 0xFFFF
pi_framebuffer_t *fb = NULL;

void openDisplay(void)
{
   if(fb==NULL)
   {
       fb=getFrameBuffer();
   }
}

void closeDisplay(void)
{
   if(fb)
   {
       clearFrameBuffer(fb,BLACK);
       freeFrameBuffer(fb);
       fb=NULL;
   }
}

void displayLetter(char letter, int xOffset, int yOffset)
{
   if(fb == NULL)
   {
       fprintf(stderr,"Tried to draw (%d,%d) to a non-existent frame buffer!\n",xOffset,yOffset);
       return;
   }
   sense_fb_bitmap_t *bm=fb->bitmap;
   clearFrameBuffer(fb,BLACK);

   xOffset=(xOffset%8+8)%8;
   yOffset=(yOffset%8+8)%8;

   if(letter == 'Y')
   {
       bm->pixel[(1+yOffset)%8][(1+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(2+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(3+xOffset)%8]=WHITE;
       bm->pixel[(2+yOffset)%8][(4+xOffset)%8]=WHITE;
       bm->pixel[(3+yOffset)%8][(5+xOffset)%8]=WHITE;
       bm->pixel[(3+yOffset)%8][(6+xOffset)%8]=WHITE;
       bm->pixel[(3+yOffset)%8][(7+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(1+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(2+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(3+xOffset)%8]=WHITE;
       bm->pixel[(5+yOffset)%8][(4+xOffset)%8]=WHITE;
       bm->pixel[(4+yOffset)%8][(5+xOffset)%8]=WHITE;
       bm->pixel[(4+yOffset)%8][(6+xOffset)%8]=WHITE;
       bm->pixel[(4+yOffset)%8][(7+xOffset)%8]=WHITE;
   }

   else if(letter == 'N')
   {
       bm->pixel[(1+yOffset)%8][(1+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(2+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(3+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(4+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(5+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(6+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(7+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(1+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(2+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(3+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(4+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(5+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(6+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(7+xOffset)%8]=WHITE;
       bm->pixel[(5+yOffset)%8][(2+xOffset)%8]=WHITE;
       bm->pixel[(5+yOffset)%8][(3+xOffset)%8]=WHITE;
       bm->pixel[(4+yOffset)%8][(3+xOffset)%8]=WHITE;
       bm->pixel[(4+yOffset)%8][(4+xOffset)%8]=WHITE;
       bm->pixel[(3+yOffset)%8][(4+xOffset)%8]=WHITE;
       bm->pixel[(3+yOffset)%8][(5+xOffset)%8]=WHITE;
       bm->pixel[(2+yOffset)%8][(5+xOffset)%8]=WHITE;
       bm->pixel[(2+yOffset)%8][(6+xOffset)%8]=WHITE;
   }
}

void clearDisplay(void)
{
   if(fb)
   {
       clearFrameBuffer(fb,BLACK);
   }
}

Add a comment
Know the answer?
Add Answer to:
C language. A file, display.c handles all display to the LED array. It will need a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments:...

    c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of a file, a pointer to an int array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to the file, and then close the file. Write another function named fileToArray. This function should accept three argu- ments: the name of a file, a pointer to an int array, and the size...

  • u also need to store the letters' ASCII number in the freq array 4. [8] Write...

    u also need to store the letters' ASCII number in the freq array 4. [8] Write a C function with prototype · void letter_freq(const char word[], int freq []); This function computes the number of appearances of each letter in the string word and stores them in array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90...

  • Write a program in C++ that, given a seven-digit number, writes to a file every possible...

    Write a program in C++ that, given a seven-digit number, writes to a file every possible seven-letter corresponding to that number. There are 2187 (3 to the seventh power) such words. Include the numbers 0 and 1; just embed them in the words as a 0 and a 1. Example: one possibility for 5701679 would be: LR01OPW. Assume the user correctly enters only 7 digits (no ‘-‘). Read the user input into a char array. Use a recursive function to...

  • C++ ONLY!!! NOT JAVA. The standard deviation is calculated from an array X size n with...

    C++ ONLY!!! NOT JAVA. The standard deviation is calculated from an array X size n with the equation std=sqrt(sum((xi-mean)2/(n-1))) Sum the square of difference of each value with the mean. Divide that sum by n-1. Take the square root and you have the standard deviation. //System Libraries #include <iostream> //Input/Output Library #include <cstdlib> //Srand #include <ctime> //Time to set random number seed #include <cmath> //Math Library #include <iomanip> //Format Library using namespace std; //User Libraries //Global Constants, no Global Variables...

  • Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h...

    Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h (Given. Just use it, don't change it!) Student.cpp (Partially filled, need to complete) 1. Assignment description In this assignment, you will write a simple class roster management system for ASU CSE100. Step #1: First, you will need to finish the design of class Student. See the following UML diagram for Student class, the relevant header file (class declaration) is given to you as Student.h,...

  • c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each...

    c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each size Im trying to do time analysis for Quick sort but i keep getting time = 0 also i want edit the program to test different random sizes of the array and give me the time in a...

  • Program Description: (C++). Write a word search program that searches an input data file for a...

    Program Description: (C++). Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears in the input data file. In addition, the program should count and display the number of characters in the input data file that are not vowels. Your program must do this by providing the following functions : void processFile(ifstream &inFile, string &word, int &wordCount, int &nonVowelCount) ; void...

  • Write a program in C language that reads scores and id numbers from a file, finds...

    Write a program in C language that reads scores and id numbers from a file, finds the average score, and assigns each student a grade based on the following rules: Each score > average + 20 gets an A Each score between average + 10 and average + 20 gets a B Each score between average - 10 and average + 10 gets a C Each score between average - 20 and average - 10 gets a D Each score...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT