#include "stdafx.h" #include "signal.h" #include "User_Api.h" #include "PET_Type.h" #include "time.h" static volatile sig_atomic_t keep_running = 1; static void sig_handler(int _) { (void)_; keep_running = 0; } int main(void) { signal(SIGINT, sig_handler); // start portwell API PET_API_Init(); // set pin 3 & 4 as inputs PET_GPIO_SetPinDirection (1, 3, 1); PET_GPIO_SetPinDirection (1, 4, 1); // set pin 1 & 2 as outputs PET_GPIO_SetPinDirection (1, 1, 0); PET_GPIO_SetPinDirection (1, 2, 0); // pull 1 & 2 low PET_GPIO_WritePin(1, 1, 0); PET_GPIO_WritePin(1, 2, 0); unsigned char greenvalue = 0; unsigned char redvalue = 0; while (keep_running) { // read pins, print values PET_GPIO_ReadPin(1, 4, &greenvalue); PET_GPIO_ReadPin(1, 3, &redvalue); // check for button presses (0) // bring pin high if pressed, low when released // green if (greenvalue == 0) { PET_GPIO_WritePin(1, 2, 1); } else { if (greenvalue == 1) { PET_GPIO_WritePin(1, 2, 0); } //red if (redvalue == 0) { PET_GPIO_WritePin(1, 1, 1); } else { if (redvalue == 1) { PET_GPIO_WritePin(1, 1, 0); } } } } // close API PET_API_Uninit (); return EXIT_SUCCESS; }