Question

In: Computer Science

How can I edit this C code to make sure that the letter P and L...

How can I edit this C code to make sure that the letter P and L would show up separately one at a time on an interval of one second on a raspberry pi?

1 #include <stdio.h>
2 #include <unistd.h>
3 #include "sense.h"
4
5 #define WHITE 0xFFFF
6
7 int main(void) {
8     // getFrameBuffer should only get called once/program
9     pi_framebuffer_t *fb=getFrameBuffer();
10     sense_fb_bitmap_t *bm=fb->bitmap;
11
12      bm->pixel[0][0]=WHITE;
13      bm->pixel[0][1]=WHITE;
14      bm->pixel[0][2]=WHITE;
15      bm->pixel[0][3]=WHITE;
16      bm->pixel[0][4]=WHITE;
17      bm->pixel[0][5]=WHITE;
18      bm->pixel[1][5]=WHITE;
19      bm->pixel[2][5]=WHITE;
20      bm->pixel[3][5]=WHITE;
21      bm->pixel[3][4]=WHITE;
22      bm->pixel[3][3]=WHITE;
23      bm->pixel[2][3]=WHITE;
24      bm->pixel[1][3]=WHITE;
25
26
27     sleep(1);
28
29
30 bm->pixel[0][0]=WHITE;
31 bm->pixel[0][1]=WHITE;
32 bm->pixel[0][2]=WHITE;
33 bm->pixel[0][3]=WHITE;
34 bm->pixel[0][4]=WHITE;
35 bm->pixel[0][5]=WHITE;
36 bm->pixel[1][0]=WHITE;
37 bm->pixel[2][0]=WHITE;
38 bm->pixel[3][0]=WHITE;
39
40
41     /*
42     void drawCFB(void);
43     drawCFB();
44     */
45
46     sleep(1);
47     freeFrameBuffer(fb);
48     return 0;
49 }
50

Solutions

Expert Solution

The sleep() function you used is correct but since it may be sometimes the correct delay is not produced. In that case you can use the following delay function in your code.

I was not able to test your code since I do not have "sense.h" header file (as it may be your own custom header file) and also that rasberry pi apparatus too, at my home. So, I cannot see the ouput of given code.

Let me know of the issues if any in the comments below.

I hope the given delay function serves your purpose of adding one second delay.

// C function to implement the time delay functionality
#include <stdio.h>
// To use time library of C
#include <time.h>

void delay_func(int s)
{
    // To convert given time in seconds to milliseconds
    int m_s = 1000 * s;

    // To note the start time i.e. the current time of the system clock
    clock_t sys_t = clock();

    // looping until the required time is not achieved
    while (clock() < sys_t + m_s);
}

// Main code to test the above functionality
int main()
{
    int n
    for (n = 0; n < 100; n++)
    {
        // delay of one second
        delay_func(1);
        printf("%d seconds have passed\n", n + 1);
    }
    return 0;
}

Output Screenshot

The required code with the delay functionality added. Also I have changed some of the pixel arrangement for L to make L look better. If you want you can keep the arrangement or otherwise revert to your old one.

#include <stdio.h>
#include <unistd.h>

// To use time library of C
#include <time.h>

#include "sense.h"




#define WHITE 0xFFFF


void delay_func(int s)
{
    // To convert given time in seconds to milliseconds
    int m_s = 1000 * s;

    // To note the start time i.e. the current time of the system clock
    clock_t sys_t = clock();

    // looping until the required time is not achieved
    while (clock() < sys_t + m_s);
}


int main(void) {
     // getFrameBuffer should only get called once/program
     pi_framebuffer_t *fb=getFrameBuffer();
     sense_fb_bitmap_t *bm=fb->bitmap;

     
     // New Pixel arrangement for P
      bm->pixel[0][0]=WHITE;
      bm->pixel[0][1]=WHITE;
      bm->pixel[0][2]=WHITE;
      bm->pixel[0][3]=WHITE;
      bm->pixel[0][4]=WHITE;
      bm->pixel[0][5]=WHITE;
      bm->pixel[1][5]=WHITE;
      bm->pixel[2][5]=WHITE;
      // bm->pixel[3][5]=WHITE;
      bm->pixel[3][4]=WHITE;
      //bm->pixel[3][3]=WHITE;
      bm->pixel[2][3]=WHITE;
      //bm->pixel[1][3]=WHITE;
      // Added a new pixel value
      bm->pixel[1][2]=WHITE;   


     //sleep(1);
     //using delay() function instead of sleep()
     delay_func(1);  

     // Pixel arrangement for L
     bm->pixel[0][0]=WHITE;
     bm->pixel[0][1]=WHITE;
     bm->pixel[0][2]=WHITE;
     bm->pixel[0][3]=WHITE;
     bm->pixel[0][4]=WHITE;
     bm->pixel[0][5]=WHITE;
     bm->pixel[1][0]=WHITE;
     bm->pixel[2][0]=WHITE;
     bm->pixel[3][0]=WHITE;


     /*
     void drawCFB(void);
     drawCFB();
     */
     
     //sleep(1);
     //I think delay is not needed here
     //but adding it since your in code sleep is inserted here
     delay_func(1); 
     
     freeFrameBuffer(fb);
     return 0;
 }


Related Solutions

C Code Edit this code to make it output all unique letters IN LOWERCASE of an...
C Code Edit this code to make it output all unique letters IN LOWERCASE of an input file. For example, with this input: Raspberry Grapefruit Straw berry raspBERRY Blue$$berry apple Pine_apple raspberry The output should be: raspberry grapefruit straw berry blue berry apple pine NOTE: Words with different capitlization, like raspberry and raspBERRY count as 1 unique word, so raspberry should only be seen once in the output. #include <stdio.h> #include <stdlib.h> int main() {     //Pointer to access the...
I need to understand how I would edit this code without changing anything, only adding. I...
I need to understand how I would edit this code without changing anything, only adding. I am not looking for the exact answer, just information on how I would use the given code to complete some of the todo statements. Thank you! // include this header file so we can use `printf()` #include <stdio.h> // every C program must implement the `main()` function int main(int argc, char *argv[]) {    //TODO: check for enough arguments       // save the...
JAVA- How do I edit the following code as minimally as possible to add this method...
JAVA- How do I edit the following code as minimally as possible to add this method for calculating BMI? BMI Method: public static double calculateBMI(int height, int weight) { double BMI = (((double) weight) * 0.453592d) / ((((double) height) * 0.0254) * (((double) height) * 0.0254)); Format f = new DecimalFormat("##.######"); return (f.format(BMI)); } Code: import java.text.DecimalFormat; import java.util.Scanner; public class test2 { public static void main(String[] args) { DecimalFormat f = new DecimalFormat("##.0"); Scanner reader = new Scanner(System.in); System.out.printf("%10s...
Code the following in C++ and make sure to include all three files required at the...
Code the following in C++ and make sure to include all three files required at the end. Hotdogs – The World’s Greatest Cost Effective Wholesome Nutritious Food Due to world food supply scarcity and the burgeoning populations of the world’s countries, your hot stand business is globalizing to satisfy the world’s desire for a cost effective wholesome nutritious food source. Market studies have shown that tens of billions of people are craving for the eponymous hotdog which will result in...
WRITE IN C++ Add to the Coord class Edit the provided code in C++ Write a...
WRITE IN C++ Add to the Coord class Edit the provided code in C++ Write a member function named      int distance2origin() that calculates the distance from the (x, y, z) point to the origin (0, 0, 0) the ‘prototype’ in the class definition will be      int distance2origin() outside the class definition             int Coord :: distance2origin() {                         // your code } _______________________________________________________________________________________________________ /************************************************** * * program name: Coord02 * Author: * date due: 10/19/20 * remarks:...
I was not sure how to utilize this line because I made code that works but...
I was not sure how to utilize this line because I made code that works but not with this line specifically. C++ Function 2: bool exists_trio_within_distance(int*,int,int); //Input:    //an integer array (param 1), its size (param 2), and    //a distance (param 3) //Output:    //True or false //Behavior:    //Returns true is there exists    //a sequence of 3 values in the array    //such that sum of the first two elements    //is equal to the third element...
can you detail explain how solved: "is just to practice" and make sure I have the...
can you detail explain how solved: "is just to practice" and make sure I have the same answer is from the economy for engineer and scientists You are deputy chief of the Space Federation Force (SFF), which means you do whatever the chief of the SFF says. She says you evaluate at 10% per year unless told otherwise. Space Fuel Inc. is considering establishing a new propellant depot to provide space vehicles a refueling point in their trek to Mars....
C++ CODE PLEASE MAKE SURE TO USE STRINGSTREAM AND THAT THE OUTPUT NUMBER ARE CORRECT 1....
C++ CODE PLEASE MAKE SURE TO USE STRINGSTREAM AND THAT THE OUTPUT NUMBER ARE CORRECT 1. You must call all of the defined functions above in your code. You may not change function names, parameters, or return types. 2. You must use a switch statement to check the user's menu option choice. 3. You may create additional functions in addition to the required functions listed above if you would like. 4. If user provides option which is not a choice...
2. How many seven – letter code words can be formed using a standard 26 letter...
2. How many seven – letter code words can be formed using a standard 26 letter alphabet (12 points) a.         if repetition is allowed? b.         if repetition is not allowed? c.         if the first letter has to be a C and the rest of the letters are different? d.         if the first two letters have to be a vowel and the rest of the letters are different?
use repil.it edit my code please i already did all part but need to edit more...
use repil.it edit my code please i already did all part but need to edit more its run for some not shwing all intro to C-programin be sure to edit on my code very basic and add good comments thank you 1-Write a program that requests 5 integers from the user and stores them in an array. You may do this with either a for loop OR by getting a string from stdin and using sscanf to store formatted input...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT