Пример #1
0
int main(int argc, char *argv[]){
  if( argc > 1 ){
    sscanf(argv[1], "%i", &frame_time);
  }

  signal(SIGINT, sigintHandler);
  wiringPiSetupGpio();
  pinMode(PIN_CS, OUTPUT);
  pinMode(PIN_RST, OUTPUT);
  pinMode(PIN_A, OUTPUT);
  //digitalWrite(PIN_CS, LOW);
  memset(buf, 0, BUF_SIZE);
  if(wiringPiSPISetup(0, SPI_SPEED_HZ)==-1){
    printf("Could not initialize SPI\n");
    return;
  };
  lcd_reset();
  
  lcd_command((unsigned char[8]){
	0xA2,
	0xA0,
	0xC8,
	0xA4,
	0xA6,
	0x2F,
	0x60,
	0x27
		},8);
Пример #2
0
int main(void){
	printf("Prova 1: Semplice LED blinking mediante pulsante SW1 su GPIO4 (wiringPiSetupGpio)\n");
        printf("\tGli OUTPUT dei due LED sono GPIO22 e GPIO24, mediante la pressione del pulsante i due LED eseguono un lampeggio alternato\n\n");

	wiringPiSetupGpio();

        printf("wiringPiSetupGpio()\n");

        pinMode(LED1, OUTPUT);
        pinMode(LED2, OUTPUT);
        pinMode(SW1, INPUT);

	printf("Fine Setup\n");

        while(1){
                digitalWrite(LED1, 0);
                digitalWrite(LED2, 0);

		if(digitalRead(SW1)!=1){
			printf("SW1 Press\n");
                	digitalWrite(LED1, 1);
                	digitalWrite(LED2, 0);
                	delay(250);
                	digitalWrite(LED1, 0);
                	digitalWrite(LED2, 1);
                	delay(250);
		}
	}
}
Пример #3
0
/**
 * init():
 * Setup the pins for wiringPi.
 **/
void init(){
    /* Initialize the wiringPi library */
    wiringPiSetupGpio();
    pinMode(LED1, OUTPUT);
    pinMode(LED2, OUTPUT);
    pinMode(BUT1, INPUT);
}
Пример #4
0
int
main (int argc, char** argv)
{

   int status = wiringPiSetupGpio();
   if (status < 0)
   {
      printf ("Fail to setup wiringPi. Are you root?");
      exit(1);
   }

   pinMode (24,INPUT);

   wiringPiISR(24, INT_EDGE_FALLING, irq_handler);

   status = wiringPiSPISetup(0,500000);
   if (status < 0)
   {
      printf("Failed to configure SPI");
      exit (1);
   }   
   
   unsigned char buf [256];
   pause();
   while (1)
   {
      buf[0] = 0x07;
      buf[1] = 0xff;
      wiringPiSPIDataRW(0, buf, 2);
      printf ("Output %d \n",buf[1]);
      delay (1000);
      
   }
}
Пример #5
0
int main(int argc, char **argv)
{
  int g,rep, i;
 
  // Set up gpi pointer for direct register access
  wiringPiSetupGpio ();
  setup_io();
  for (i = 0; i < 28; i++)
  {
	  INP_GPIO(i);
	  printf("%d", GET_GPIO(i));
  }
  printf("\n");
  //exit(0);
  OUT_GPIO(INT); GPIO_SET(INT);
  OUT_GPIO(NMI); GPIO_SET(NMI);
  OUT_GPIO(CLK); GPIO_SET(CLK);
  OUT_GPIO(WAIT); GPIO_SET(WAIT);
  OUT_GPIO(BUSRQ); GPIO_SET(BUSRQ);
  OUT_GPIO(RESET); GPIO_SET(RESET);
  OUT_GPIO(SI); GPIO_SET(SI);
  OUT_GPIO(CP); GPIO_SET(CP);
  OUT_GPIO(CS_16); GPIO_SET(CS_16);
  OUT_GPIO(M); 
  ResetSimulationVars();  
  WriteControlPins();
  DoReset();
  
  while(1)
	  loop();
}
Пример #6
0
static void *disis_gpio_new(t_floatarg f)
{
    if (!disis_gpio_isvalidpin((int)f)) return(NULL);
    if (geteuid () != 0)
    {
        post("error: disis_gpio external requires pd-l2ork to be run with root privileges. You can achieve this by doing 'sudo pd-l2ork'. Alternately, if running pd-l2ork remotely via ssh use 'sudo -E pd-l2ork' to preserve the enviroment.") ;
        return(NULL);
    }
    //char buf[FILENAME_MAX];
    //canvas_makefilename(glist_getcanvas((t_glist*)canvas_getcurrent()), "@pd_extra/disis_gpio/chown_gpio&", buf, FILENAME_MAX);
    //if (system(buf) < 0) { // first to adjust permissions for /sys/class/gpio so that we can export
    //    post("disis_gpio: failed setting permissions to /sys/class/gpio folder");
    //    return(NULL);
    //}
    t_disis_gpio *x = (t_disis_gpio *)pd_new(disis_gpio_class);
    x->x_out1 = outlet_new(&x->x_obj, gensym("float"));
    x->x_out2 = outlet_new(&x->x_obj, gensym("float"));
    x->x_fdvalue = -1;
    x->x_pin = f;
    x->x_export = 0;
    x->x_dir = 0;
    x->x_pwm = 0;
    x->x_softpwm_thread = -1;
 
    x->x_params.p_pin = &(x->x_pin);
    x->x_params.p_val = &(x->x_softpwmval);
    x->x_params.p_thread = &(x->x_softpwm_thread);

    wiringPiSetupGpio();
    //x->x_pwmrange = 0;
    //x->x_chown = gensym(buf);
    return (x);
}
Пример #7
0
int main(int argc, char **argv)
{
    wiringPiSetupGpio();
    pimobileInitializeGpio();
    
    printf("Testing forward movement at full speed\n");
    pimobileSetMotorsSpeedAndDirection(100,100,1,1);
    sleep(1);

    printf("Testing forward movement at 40%% speed\n");
    pimobileSetMotorsSpeedAndDirection(40,40,1,1);
    sleep(1);

    printf("Testing backward movement at full speed\n");
    pimobileSetMotorsSpeedAndDirection(100,100,0,0);
    sleep(1);

    printf("Testing backward movement at 40%% speed\n");
    pimobileSetMotorsSpeedAndDirection(40,40,0,0);
    sleep(1);

    printf("Testing turning and compass. Turning to 0° North\n");
    pimobileTurnTo(0);
    sleep(1);

    printf("Testing turning and compass. Turning to 180° South\n");
    pimobileTurnTo(180);
    sleep(1);

    return 0;
}
Пример #8
0
/*****************************************
 * WiringPi launcher to set PWM          *
 * based on James Ward PWM settings      *
 * to work with SSR and Espresso machine *
 *****************************************/
int main (int argc, char *argv[])
{
  int drive = 0;
  int reto = 0;

  if(argc != 2)
  {
	printf("Error: invalid arguments. Usage: sudo pwmlauncher <aaa> where aaa is the drive percent\n");
	exit(0); 
  }
  //printf ("Welcome into PWM drive launcher\n") ;
  //retrieve argument
  drive = atoi(argv[1]);
  if(drive > 100)
    drive = 100;
  printf("drive=%d%\n",drive);

  //init wiringpi
  if (wiringPiSetupGpio() == -1){
    printf("Error inint wiringpi lib\n");
    exit (1) ;
  }

  //PWM mode
  pinMode(18,PWM_OUTPUT);
  //PWM "predictive mode"
  pwmSetMode(PWM_MODE_MS); 

  //set clock at 2Hz (clock divider / range)
  pwmSetClock(PWCLKDIVIDER);
  pwmSetRange (PWRANGE) ;
  //setting drive according to the RANGE 
  pwmWrite (18, (drive * (PWRANGE / 100))); 
}
Пример #9
0
int main(void)
{
  if(wiringPiSetupGpio() == -1) 
    return 1;

  pinMode(LED1, OUTPUT); 
  pinMode(LED2, OUTPUT); 

  pinMode(SW, INPUT); 


  while(1)
  {
    digitalWrite(LED1, 0);
    digitalWrite(LED2, 0); 

    if(digitalRead(SW) == 1) 
    {
      digitalWrite(LED1, 1);
      digitalWrite(LED2, 1);
      delay(1000);
    }
  }
  return 0 ;
}
Пример #10
0
int main(int argc, char* argv[])
{
	// WiringPiを初期化
	if( wiringPiSetupGpio() == -1 ){
		printf("failed to wiringPiSetupGpio()\n");
		return 1;
	}
	
	// GPIO_A を出力に設定
	pinMode(GPIO_A, OUTPUT);

	// GPIO_Bを入力に設定
	pinMode(GPIO_B, INPUT);

	// EXEC_CNT分処理を繰り返す
	int i=0;
	while(i<=EXEC_CNT){
		// GPIO_Bの状態を読み込み
		int val = digitalRead(GPIO_B);
		printf("%03d: GPIO_B is %d\n",i,val);
		if(val>0){
			// GPIO_AをON(Highレベル)にする
			digitalWrite(GPIO_A, HIGH);
		}else{
			// GPIO_AをOFF(Lowレベル)にする。
			digitalWrite(GPIO_A, LOW);
		}

		i++;
		usleep(DELAY_USEC);
	}

	return 0;
}
Пример #11
0
int main(void)
{
	wiringPiSetup(); // Initializes wiringPi using wiringPi's simlified number system.
	wiringPiSetupGpio(); // Initializes wiringPi using the Broadcom GPIO pin numbers

	pinMode (17, OUTPUT);

	pinMode(4, INPUT);
	char mychar = 0;
	while(mychar==0)
	{
		if (digitalRead(4))
		{
//    			printf("1\n");
			digitalWrite (17, HIGH);
		}
		else
    		{
//			printf("0\n");
			digitalWrite (17, LOW);
		}
//	usleep(150000);

	}
}
Пример #12
0
/*!
*  Initialisation du module
*
*/
void CRaspiGPIO::init(CApplication *application)
{
  CModule::init(application);
  setGUI(&m_ihm); // indique à la classe de base l'IHM

  // Gère les actions sur clic droit sur le panel graphique du module
  m_ihm.setContextMenuPolicy(Qt::CustomContextMenu);
  connect(&m_ihm, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onRightClicGUI(QPoint)));
  
  // Restore la taille de la fenêtre
  QVariant val;
  val = m_application->m_eeprom->read(getName(), "geometry", QRect(50, 50, 150, 150));
  m_ihm.setGeometry(val.toRect());
  // Restore le fait que la fenêtre est visible ou non
  val = m_application->m_eeprom->read(getName(), "visible", QVariant(true));
  if (val.toBool()) { m_ihm.show(); }
  else              { m_ihm.hide(); }
  // Restore le niveau d'affichage
  val = m_application->m_eeprom->read(getName(), "niveau_trace", QVariant(MSG_TOUS));
  setNiveauTrace(val.toUInt());
  // Restore la couleur de fond
  val = m_application->m_eeprom->read(getName(), "background_color", QVariant(DEFAULT_MODULE_COLOR));
  setBackgroundColor(val.value<QColor>());

  wiringPiSetupGpio(); // Utilise la numérotation de pin BCM

  for (unsigned int i=0; i<MAX_GPIO_COUNT; i++) {
      // Recherche dans le fichier EEPROM une configuration de type "gpio_<i>=input pull down"
      // gpio_17 = input
      QString eeprom_config_name = "gpio_" + QString::number(i);
      val = m_application->m_eeprom->read(getName(), eeprom_config_name, QVariant());
      if (val != QVariant()) {  // le paramètre a été trouvé -> le GPIO est utilisé et doit être configuré
          configPinMode(i, val.toString());
      }

      // Initialise la liste des GPIO dans la liste déroulante de configuration
      // on part des contrôles affichés sur l'interface et on récupère les numéros
      // Rensigne dans la liste déroulante des GPIO tous les numéros possibles de GPIO
      QLabel *lbl = m_ihm.findChild<QLabel*>(PREFIX_MODE_GPIO + QString::number(i)); // "mode_GPIO_<i>" c'est le nom de tous les labels des GPIO sur l'IHM pour indiquer si c'est une entrée / sortie / ...
      if (lbl) {
          m_ihm.ui.configChoixGPIO->addItem("GPIO " + QString::number(i));
      }
      // connexion signal/slot avec toutes les checkbox qui permettent d'écrire sur le port
      // on repert toutes les checkbox par leur nom "write_GPIO_<i>"
      QCheckBox *checkbox = m_ihm.findChild<QCheckBox*>(PREFIX_CHECKBOX_WRITE + QString::number(i));
      if (checkbox) {
          connect(checkbox, SIGNAL(clicked(bool)), this, SLOT(onWritePinChange(bool)));
      }
  }

  // Renseigne dans la liste déroulante des configurations possibles
  QStringList list_modes;
  list_modes << "" << "Input" << "Input pull down" << "Input pull up" << "Output" << "PWM Output";
  m_ihm.ui.configChoixMode->addItems(list_modes);

  connect(m_ihm.ui.configChoixGPIO, SIGNAL(activated(int)), this, SLOT(onChoixConfigGPIO()));
  connect(m_ihm.ui.configChoixMode, SIGNAL(activated(QString)), this, SLOT(onChoixConfigMode(QString)));
  connect(&m_timer_read, SIGNAL(timeout()), this, SLOT(readAllInputs()));
  m_timer_read.start(100);
}
Пример #13
0
int main(int argc, char* argv[]) {
    wiringPiSetupGpio(); // Initialize wiringPi -- using Broadcom pin numbers

    pinMode(BCM_FIRST_GATE, INPUT);
    pinMode(LED_FIRST_GATE, OUTPUT);
    pinMode(BCM_SECOND_GATE, INPUT);
    pinMode(LED_SECOND_GATE, OUTPUT);
    pinMode(BCM_ULTRASONIC_ECHO, INPUT);
    pinMode(BCM_ULTRASONIC_TRIGGER, OUTPUT);
    
    if (wiringPiISR(BCM_FIRST_GATE, INT_EDGE_BOTH, &FIRST_GATE_PASS)  < 0) {
        printf("Unable to setup ISR (FIRST_GATE) for GPIO %d (%s)\n\n", BCM_FIRST_GATE, strerror(errno));
        exit(1);
    }
    if (wiringPiISR(BCM_SECOND_GATE, INT_EDGE_BOTH, &SECOND_GATE_PASS)  < 0) {
        printf("Unable to setup ISR (SECOND_GATE) for GPIO %d (%s)\n\n", BCM_SECOND_GATE, strerror(errno));
        exit(1);
    }
    if (wiringPiISR(BCM_ULTRASONIC_ECHO, INT_EDGE_BOTH, &ISR_ECHO)  < 0) {
        printf("Unable to setup ISR (ULTRASONIC) for GPIO %d (%s)\n\n", BCM_ULTRASONIC_ECHO, strerror(errno));
        exit(1);
    }
	
    while (true) {
            usleep(100);
    }
    return 0;
}
Пример #14
0
bool LED::init() {
  // GPIO setup
  if (wiringPiSetupGpio() == -1) {
    fprintf(stderr, "[ERROR] wiringPiSetupGpio() failed\n");
    return false;
  }

  // setup pin mode
  pinMode(LED_OUT_A, OUTPUT);
  pinMode(LED_OUT_B, OUTPUT);
  pinMode(LED_OUT_C, OUTPUT);
  pinMode(LED_OUT_1, OUTPUT);
  pinMode(LED_OUT_2, OUTPUT);
  pinMode(LED_OUT_3, OUTPUT);
  pinMode(LED_OUT_4, OUTPUT);

  // clear all bit
  digitalWrite(LED_OUT_A, 0);
  digitalWrite(LED_OUT_B, 0);
  digitalWrite(LED_OUT_C, 0);
  digitalWrite(LED_OUT_1, 1);
  digitalWrite(LED_OUT_2, 1);
  digitalWrite(LED_OUT_3, 1);
  digitalWrite(LED_OUT_4, 1);

  return true;
}
Пример #15
0
void displayString(){
	wiringPiSetupGpio();

	int fd = lcdInit(
	    //LCDCONFIG
	    //rows
	    4,
	    //colums
	    20,
	    //bits
	    4,


	    //PINLAYOUT
	    //RS (function select
	    12, 
	    //strobe, E (Enable Signal
	    16, 
	    //d0 - d7, the data pints
	    26,17,21,19,0,0,0,0
	    //0,0,0,0,5,6,13,19
		    );
	lcdHome(fd);
	lcdClear(fd);

	lcdPuts(fd, "GORGABAL");
}
Пример #16
0
void setup (void)
{
   int status = wiringPiSetupGpio();
   if(status < 0)
   {
      perror ("Failed to configure GPIO");
      exit (1);
   }

   pinMode (IRQ_PIN, INPUT);
   pinMode (CE_PIN, OUTPUT);

   status = wiringPiSPISetup (CHANNEL,SPEED);    
   if (status < 0)
   {
      perror ("Failed to configure SPI");
      exit(1);
   }

   configure_address();
   //TODO dynamic length nrf24l01_set_dynamic_payload_length(0, ENABLE);
   configure_isr();
      
   nrf24l01_set_rx_payload_length(1,32);
   //nrf24l01_set_en_aa(1,ENABLE);
   nrf24l01_set_dynamic_payload_length(1, ENABLE);
   nrf24l01_power_up(ENABLE);
   nrf24l01_mode(MODE_RX);
   printf ("Configured\n");
}
Пример #17
0
int main(int argc, char* argv[])
{
	// WiringPiを初期化
	if( wiringPiSetupGpio() == -1 ){
		printf("failed to wiringPiSetupGpio()\n");
		return 1;
	}
	
	// GPIO_A を出力に設定
	pinMode(GPIO_A, OUTPUT);

	// GPIO_Bを入力に設定
	pinMode(GPIO_B, OUTPUT);
    
    struct timeval stNow;	// 現時刻取得用
    struct timeval stLen;	// 任意時間
    struct timeval stEnd;	// 現時刻から任意時間経過した時刻
    timerclear(&stNow);
    timerclear(&stLen);
    timerclear(&stEnd);
    
    int forward_sec     = DEF_FORWARD_SEC;
    int backward_sec    = DEF_BACKWARD_SEC;
    int interval_sec    = DEF_INTERVAL_SEC;
    int loop_num        = DEF_LOOP_NUM;
    std::cout << "input forward sec(DEF:" << forward_sec << "):";
    {
        std::string input;
        std::getline( std::cin, input);
        if( !input.empty() ){
            std::istringstream stream(input);
            stream >> forward_sec;
        }
    }
Пример #18
0
int wiringSetup ()
{
	int i=0;
	const char *pins_numbering = getenv ("PINS_NUMBERING");
	const char *grovepi = getenv ("GROVE_PI");
	int addr_grovepi = -1;
	if (pins_numbering != NULL && strncmp (pins_numbering, "GPIO", 5)==0)
	{
		wiringPiSetupGpio();
	}
	else
	if (pins_numbering != NULL && strncmp (pins_numbering, "PHYSICAL", 9)==0)
	{
		wiringPiSetupPhys();
	}
	else
	{
		wiringPiSetup ();
	}
	if (grovepi) sscanf (grovepi, "%d", &addr_grovepi);
	if (addr_grovepi > -1)
	{
		grovepiSetup (addr_grovepi, 4);
	}
	for (i=0; i<MAX_SPI_BUSES; i++) spi_buses[i]=-1;
	for (i=0; i<MAX_SERIAL_BUSES; i++) serial_buses[i]=NULL;
	i2c_init ();
}
Пример #19
0
int main(int argc, const char *argv[]) {
    unsigned int timeBase = 3000000;
    char buffer[10];
    char prevLine[10];

    if (geteuid() != 0) {
        // chown root <file>
        // sudo chmod u+s <file>
        char *exec = rindex(argv[0], '/');
        exec++;
        fprintf(stderr, "You must be root to run \"%s\". Program should be suid root. This is an error.\n", exec) ;
        return 1;
    }

    atexit(destroy);
    signal(SIGHUP, terminated);
    signal(SIGINT, terminated);
    signal(SIGKILL, terminated);
    signal(SIGPIPE, terminated);
    signal(SIGALRM, terminated);
    signal(SIGTERM, terminated);

    wiringPiSetupGpio();
    pinMode(18, PWM_OUTPUT);
    pwmSetMode(PWM_MODE_MS);
    pwmWrite(18, 0);

    char tone[3] = "--";
    int octave;
    unsigned int duration;

    char *line = fgets(buffer, 10, stdin);
    assert(line != NULL);

    int parsed = sscanf(line, "%c%c%i %i", &tone[0], &tone[1], &octave, &duration);

    while (parsed == 4) {
        printf("%s%i, 1/%i\n", tone, octave, duration);
        fflush(stdout);
        int divisor = 1 << (8 - octave - 2);
        int toneIndex = 0;

        for (toneIndex = 0; toneIndex < 13; toneIndex++) {
            if (0 == strncmp(tone, TONE_NAME[toneIndex], 2)) {
                break;
            }
        }

        assert(toneIndex < 13);

        if (toneIndex < 12) {
            float frequency = TONE_HZ[toneIndex] / divisor;
            unsigned int range = (unsigned int)(600000.0f / frequency);
            pwmSetRange(range);
            pwmWrite(18, range >> 1);
            usleep(timeBase / duration);
            pwmWrite(18, 0);
            usleep(20000);
        } else {
Пример #20
0
	void initialize()
	{
		#ifdef USE_WIRING_PI
			wiringPiSetupGpio();
		#else
			std::cout << "wiringPiSetupGpio();" << std::endl;
		#endif
	}
Пример #21
0
static foreign_t
pl_wiringPiSetupGpio(){
	if(wiringPiSetupGpio() != 0){
		printf("\nwiringPiSetup failed\n");
		PL_fail;
	}
	PL_succeed;
}
Пример #22
0
int main (int argc, char *argv[])
{
    unsigned long  pulsewidth;
    if (wiringPiSetupGpio () == -1)
    {
        fprintf (stderr, “Can’t initialise wiringPi: %s\n”, strerror (errno)) ;
        return 1 ;
    }
Пример #23
0
int main(int argc, char** argv)
{
  int pin_value {0};

  if (wiringPiSetupGpio() == -1)
  {
     std::cout << "ERROR" << std::endl;
     return -1;
  }

  pinMode(START_SW_PIN, INPUT);

  pin_value = digitalRead(START_SW_PIN);
  while(pin_value != 0)
  {
    pin_value = digitalRead(START_SW_PIN);
  }

  ros::init(argc, argv, "dcmotor_target_value"); //ノード名の初期化

  ros::NodeHandle nh; //ノードハンドル宣言

  ros::Publisher dcmotor_command_pub = nh.advertise<rcr2018::DcmCommand>("dcm_command", 1); //パブリッシャの設定

  rcr2018::DcmCommand dcm;

  ros::Subscriber dcmotor_command_sub {nh.subscribe<rcr2018::TofFront>("tof_front", 1,
    std::function<void (const rcr2018::TofFront::ConstPtr&)>
    {
      [&](const auto& constptr)
      {
	std::cout << "arg_vel_max:" << arg_vel_max << std::endl;
        double target_value {0.0}; //目標値の初期化
        if (is_finished) //終了判定
        {
          target_value = 0.0;
        }
        else
        {
          target_value = arg_vel_max * normalize_sig(constptr->front); //目標角速度の決定
          // target_value = arg_vel_max * sigmoid(constptr->front); //目標角速度の決定

        }
	std::cout << "target_value:" << target_value << std::endl;

        dcm.cmd_vel = target_value; //目標角速度をメッセージに代入

        dcmotor_command_pub.publish(dcm); //パブリッシュ
      }
    }
  )}; //tofサブスクライバの設定

  ros::Subscriber line_count_sub {nh.subscribe("line_count", 1, linemsgCallback)}; //linecountサブスクライバの設定

  ros::spin();

  return EXIT_SUCCESS;
}
Пример #24
0
int main(void)
{
        wiringPiSetup(); // Initializes wiringPi using wiringPi's simlified number system.
        wiringPiSetupGpio(); // Initializes wiringPi using the Broadcom GPIO pin numbers

        pinMode (17, OUTPUT);
		digitalWrite (17, HIGH) ; delay (500) ;
		digitalWrite (17,  LOW) ; delay (500) ;
}
Пример #25
0
int main(void){
wiringPiSetupGpio();

int Ran = 0;            // Define random variable
pinMode(3, INPUT);


while (1){              // While GPIO is not being read, start looping
++Ran;                  // Increment variable by one
printf("%d \n", Ran);   // Print variable
if (Ran > 6){           // Is variable under 6?...
Ran = 0;                // ...if not, reset it to Zero.
}

while (digitalRead(3)){ // While GPIO Pin 3 is HIGH...

if (Ran == 1) {         //... Check variable against the following and play a file accordingly.
printf("%d \n", Ran);   // Print variable (for debugging)
system("mplayer bass/bass4.wav"); // Call mplayer to play audio file
Ran = 0;                // Reset variable to Zero so audio doesn't play again until we reset GPIO
}

if (Ran == 2) {
printf("%d \n", Ran);
system("mplayer bass/bass7.wav");
Ran = 0;
}

if (Ran == 3) {
printf("%d \n", Ran);
system("mplayer bass/bass8.wav");
Ran = 0;
}

if (Ran == 4) {
printf("%d \n", Ran);
system("mplayer bass/bass19.wav");
Ran = 0;
}

if (Ran == 5) {
printf("%d \n", Ran);
system("mplayer bass/bass23.wav");
Ran = 0;
}

if (Ran == 6) {
printf("%d \n", Ran);
system("mplayer bass/bass22.wav");
Ran = 0;
}

}
}
return 0;
}
Пример #26
0
bool CommandHandler::init()
{
    if (wiringPiSetupGpio() == -1)
        return false;

    pinMode(pin, OUTPUT);
    digitalWrite(pin, 1);
    digitalWrite(pin, 0);
    return true;
}
Пример #27
0
/* wiringPiSetupGpio
 *
 * Parameters: None
 * Return Type: int
 */
mrb_value
mrb_Pi_wiringPiSetupGpio(mrb_state* mrb, mrb_value self) {
  /* Invocation */
  int result = wiringPiSetupGpio();

  /* Box the return value */
  mrb_value return_value = mrb_fixnum_value(result);

  return return_value;
}
/** @brief Pin initialisation
*/
void VirtualSPISlaveInit(void){
	wiringPiSetupGpio();
	
	pinMode(SLAVE_MOSI, INPUT);
	pinMode(SLAVE_MISO, OUTPUT);
	pinMode(SLAVE_SCLK, INPUT);
	//pinMode(SLAVE_CS, OUTPUT);
	
	wiringPiISR(SLAVE_SCLK, INT_EDGE_FALLING, &SPI_SLAVE_ISR) ;
}
/** @brief VirtualSPIInit
 *  @param shieldVersion:the configured shield Version
 */
void VirtualSPIInit(uint32_t shieldVersion){
	wiringPiSetupGpio();
	selectedShieldVersion = shieldVersion;
	pinMode(MOSI, OUTPUT);
	pinMode(MISO, INPUT);
	pinMode(SCLK, OUTPUT);
	if (selectedShieldVersion < 4){
		pinMode(CS, OUTPUT);
	}
	delay(30);
}
Пример #30
-1
int main (void)
{
  printf ("Raspberry Pi wiringPi GPIO speed test program\n") ;
  printf ("=============================================\n") ;

// Start the standard way

  printf ("\nNative wiringPi method: (%8d iterations)\n", FAST_COUNT) ;
  wiringPiSetup () ;
  pinMode (7, OUTPUT) ;
  speedTest (7, FAST_COUNT) ;

// GPIO

  printf ("\nNative GPIO method: (%8d iterations)\n", FAST_COUNT) ;
  wiringPiSetupGpio () ;
  pinMode (7, OUTPUT) ;
  speedTest (7, FAST_COUNT) ;

// Phys

  printf ("\nPhysical pin GPIO method: (%8d iterations)\n", FAST_COUNT) ;
  wiringPiSetupPhys () ;
  pinMode (7, OUTPUT) ;
  speedTest (7, FAST_COUNT) ;

// Switch to SYS mode:

  system ("/usr/bin/gpio export 7 out") ;
  printf ("\n/sys/class/gpio method: (%8d iterations)\n", SLOW_COUNT) ;
  wiringPiSetupSys () ;
  speedTest (7, SLOW_COUNT) ;

  return 0 ;
}