User Tools

Site Tools


user:jcavalu3:portfolio:hpcexperiment7

Vibrating Raspberry Pi

One side project I did was making a cell phone buzzer vibrate using the gpio pins on the raspberry pi. What the code does is it counts down from whatever time you input, in seconds, and once it hits zero seconds, the buzzer vibrates for one second on, one second off, until the program is quit.

The code:

  1 #include "rpi.h"
  2 #include <stdlib.h>
  3 
  4 int main()
  5 {
  6 
  7     if(map_peripheral(&gpio) == -1)
  8     {
  9         printf("Failed to map the physical GPIO registers into the virtual memory space.\n");
 10         return -1;
 11     }
 12 
 13     int read = 0;
 14 
 15     INP_GPIO(11);
 16     OUT_GPIO(11);
 17 
 18     int countdown = 0;
 19 
 20     printf("Welcome to THE COUNTDOWN.\nHow long would you like to COUNT DOWN: ");
 21     scanf("%d", &countdown);
 22 
 23     printf("PREPARE FOR THE COUNTDOWN.\nStarting at: %u seconds\n\n", countdown);
 24 
 25     for(countdown; countdown >= 0; countdown--)
 26     {
 27         printf("%u\n", countdown);
 28         usleep(1000000);
 29     }
 30 
 31     printf("GAME OVER, BITCH.\n");
 32 
 33     while(1)
 34     {
 35 
 36         GPIO_SET = 1 <<  11;
 37         usleep(1000000);
 38         read = GPIO_READ(11);
 39         read = read >> 11;
 40         printf("\nPIN: %u", read);
 41         GPIO_CLR = 1 <<  11;
 42         usleep(1000000);
 43         read = GPIO_READ(11);
 44         read = read >> 11;
 45         printf("\nPIN: %u", read);
 46     }
 47 
 48     return(0);
 49 }
user/jcavalu3/portfolio/hpcexperiment7.txt · Last modified: 2013/12/13 16:53 by jcavalu3