void IOTest(void) { int p; PMD1bits.AD1MD = 1; PMD3bits.AD2MD = 1; // Set as inputs for (p=0; p<NUM_PINS_IN_GROUP_1+NUM_PINS_IN_GROUP_2; p++) { setPinState(p, INPUT); } delay(1000); // Test that we're all pulled high for (p=0; p<NUM_PINS_IN_GROUP_1+NUM_PINS_IN_GROUP_2; p++) { if (getPinValue(p) == 0) failPin(p, 1); } int testPin; for (testPin=0; testPin<NUM_PINS_IN_GROUP_1; testPin++) { // Set testPin in group 1 to output low setPinState(PIN_IN_GROUP(1,testPin), OUTPUT); setPinValue(PIN_IN_GROUP(1,testPin), 0); delay(1000); // Test that group 1 is low, and 2 is high for (p=0; p<NUM_PINS_IN_GROUP_1; p++) { if (p == testPin) continue; if (getPinValue(PIN_IN_GROUP(1,p)) == 1) failPin(PIN_IN_GROUP(1,p), 2); } for (p=0; p<NUM_PINS_IN_GROUP_2; p++) { if (getPinValue(PIN_IN_GROUP(2,p)) == 0) failPin(PIN_IN_GROUP(2,p), 3); } setPinState(PIN_IN_GROUP(1,testPin), INPUT); } for (testPin=0; testPin<NUM_PINS_IN_GROUP_2; testPin++) { // Set testPin in group 2 to output low setPinState(PIN_IN_GROUP(2,testPin), OUTPUT); setPinValue(PIN_IN_GROUP(2,testPin), 0); delay(1000); // Test that group 1 is high, and 2 is low for (p=0; p<NUM_PINS_IN_GROUP_1; p++) { if (getPinValue(PIN_IN_GROUP(1,p)) == 0) failPin(PIN_IN_GROUP(1,p), 4); } for (p=0; p<NUM_PINS_IN_GROUP_2; p++) { if (p == testPin) continue; if (getPinValue(PIN_IN_GROUP(2,p)) == 1) failPin(PIN_IN_GROUP(2,p), 5); } setPinState(PIN_IN_GROUP(2,testPin), INPUT); } PMD1bits.AD1MD = 0; PMD3bits.AD2MD = 0; }
int main(){ //Nota* notas_saved = NULL; //INPUT initGPIO(GPIO_F1, MODULO_2, DIR_INPUT); initGPIO(GPIO_F2, MODULO_2, DIR_INPUT); initGPIO(GPIO_F3, MODULO_2, DIR_INPUT); initGPIO(GPIO_F4, MODULO_2, DIR_INPUT); //OUTPUT initGPIO(LED_F1, MODULO_2, DIR_OUTPUT); initGPIO(LED_F2, MODULO_2, DIR_OUTPUT); initGPIO(LED_F3, MODULO_2, DIR_OUTPUT); initGPIO(LED_F4, MODULO_2, DIR_OUTPUT); initGPIO(BUZZER, MODULO_2, DIR_OUTPUT); initGPIO(LED_WAIT, MODULO_2, DIR_OUTPUT); while(TRUE){ blink(LED_WAIT, MODULO_2); if(getPinValue(GPIO_F1, MODULO_2)){ //notas_saved = insertLista(notas_saved, LED_F1, FREQUENCIA_1); GPIOHigh(LED_F1, MODULO_2); playNota(BUZZER, MODULO_2, FREQUENCIA_1); } GPIOLow(LED_F1, MODULO_2); if(getPinValue(GPIO_F2, MODULO_2)){ //notas_saved = insertLista(notas_saved, LED_F2, FREQUENCIA_2); GPIOHigh(LED_F2, MODULO_2); playNota(BUZZER, MODULO_2, FREQUENCIA_2); } GPIOLow(LED_F2, MODULO_2); if(getPinValue(GPIO_F3, MODULO_2)){ //notas_saved = insertLista(notas_saved, LED_F3, FREQUENCIA_3); GPIOHigh(LED_F3, MODULO_2); playNota(BUZZER, MODULO_2, FREQUENCIA_3); } GPIOLow(LED_F3, MODULO_2); if(getPinValue(GPIO_F4, MODULO_2)){ //notas_saved = insertLista(notas_saved, LED_F4, FREQUENCIA_4); GPIOHigh(LED_F4, MODULO_2); playNota(BUZZER, MODULO_2, FREQUENCIA_4); } GPIOLow(LED_F4, MODULO_2); /* if(getPinValue(GPIO_PLAY, MODULO_2)){ playMusicSaved(notas_saved); } */ } }
int countPeopleOutFunc () { int x = getPinValue(GPIO_PIN2); if (x == 0 ) { idleCount = 0; if (flagIn == 0) { flagOut = 1; countPeopleOut += 1; } else { countPeopleIn -= 1; count += 1; if(countPeopleIn ==0 ) flagIn = 0; } } else { idleCount +=1; if(idleCount >= 40 ) { countUpdate(); } } //printf(" countOut: %d\n", countPeopleOut); }
void printAllPinValues(OutputStream* outputStream) { int i = 0; for (i = PIN_MIN_INDEX; i <= PIN_MAX_INDEX; i++) { BOOL value = getPinValue(i); appendString(outputStream, "Pin "); appendHex2(outputStream, i); append(outputStream, '='); appendBOOL(outputStream, value); println(outputStream); } }
void devicePinHandleRawData(char header, InputStream* inputStream, OutputStream* outputStream) { if (header == COMMAND_SET_PIN_VALUE) { int pinIndex = readHex2(inputStream); int pinValue = readHex2(inputStream); appendAck(outputStream); setPinValue(pinIndex, pinValue); append(outputStream, COMMAND_SET_PIN_VALUE); } else if (header == COMMAND_GET_PIN_VALUE) { int pinIndex = readHex2(inputStream); appendAck(outputStream); int pinValue = getPinValue(pinIndex); // Response append(outputStream, COMMAND_GET_PIN_VALUE); appendHex2(outputStream, pinValue); } }
uint8_t digitalRead(uint8_t pin) { uint8_t timer = digitalPinToTimer(pin); uint8_t bit = digitalPinToBitMask(pin); uint8_t port = digitalPinToPort(pin); t_SetPortCfg cfg; if (timer != NOT_ON_TIMER) turnOffPWM(timer); if(port == NOT_A_PIN) { return 0; } cfg.pID = (uint16_t)portModeRegister(port); return getPinValue(cfg.pID,bit); }
void IOTest(void) { int g; PMD1bits.AD1MD = 1; PMD3bits.AD2MD = 1; for (g=0; g<=10; g++) { // Set as inputs setPinState(PIN_IN_GROUP(g,0), INPUT); setPinState(PIN_IN_GROUP(g,1), INPUT); setPinState(PIN_IN_GROUP(g,2), INPUT); setPinState(PIN_IN_GROUP(g,3), INPUT); if (g == 10) setPinState(PIN_IN_GROUP(g,4), INPUT); delay(1000); // Fail if low if (getPinValue(PIN_IN_GROUP(g,0)) == 0) failPin(PIN_IN_GROUP(g,0), 0); if (getPinValue(PIN_IN_GROUP(g,1)) == 0) failPin(PIN_IN_GROUP(g,1), 0); if (getPinValue(PIN_IN_GROUP(g,2)) == 0) failPin(PIN_IN_GROUP(g,2), 0); if (getPinValue(PIN_IN_GROUP(g,3)) == 0) failPin(PIN_IN_GROUP(g,3), 0); if (g == 10 && getPinValue(PIN_IN_GROUP(g,4)) == 0) failPin(PIN_IN_GROUP(g,4), 0); // Set pin A as output low setPinState(PIN_IN_GROUP(g,0), OUTPUT); setPinValue(PIN_IN_GROUP(g,0), 0); delay(1000); // Fail if C is high or if B or D is low if (getPinValue(PIN_IN_GROUP(g,1)) == 0) failPin(PIN_IN_GROUP(g,1), 1); if (getPinValue(PIN_IN_GROUP(g,2)) == 1) failPin(PIN_IN_GROUP(g,2), 1); if (getPinValue(PIN_IN_GROUP(g,3)) == 0) failPin(PIN_IN_GROUP(g,3), 1); if (g == 10 && getPinValue(PIN_IN_GROUP(g,4)) == 1) failPin(PIN_IN_GROUP(g,4), 1); // Set pin B as output low setPinState(PIN_IN_GROUP(g,0), INPUT); setPinState(PIN_IN_GROUP(g,1), OUTPUT); setPinValue (PIN_IN_GROUP(g,1), 0); delay(1000); // Fail if D is high or if A or C is low if (getPinValue(PIN_IN_GROUP(g,0)) == 0) failPin(PIN_IN_GROUP(g,0), 2); if (getPinValue(PIN_IN_GROUP(g,2)) == 0) failPin(PIN_IN_GROUP(g,2), 2); if (getPinValue(PIN_IN_GROUP(g,3)) == 1) failPin(PIN_IN_GROUP(g,3), 2); if (g == 10 && getPinValue(PIN_IN_GROUP(g,4)) == 0) failPin(PIN_IN_GROUP(g,4), 2); // Set pin C as output low setPinState(PIN_IN_GROUP(g,1), INPUT); setPinState(PIN_IN_GROUP(g,2), OUTPUT); setPinValue (PIN_IN_GROUP(g,2), 0); delay(1000); // Fail if A is high or if B or D is low if (getPinValue(PIN_IN_GROUP(g,0)) == 1) failPin(PIN_IN_GROUP(g,0), 3); if (getPinValue(PIN_IN_GROUP(g,1)) == 0) failPin(PIN_IN_GROUP(g,1), 3); if (getPinValue(PIN_IN_GROUP(g,3)) == 0) failPin(PIN_IN_GROUP(g,3), 3); if (g == 10 && getPinValue(PIN_IN_GROUP(g,4)) == 1) failPin(PIN_IN_GROUP(g,4), 3); // Set pin D as output low setPinState(PIN_IN_GROUP(g,2), INPUT); setPinState(PIN_IN_GROUP(g,3), OUTPUT); setPinValue (PIN_IN_GROUP(g,3), 0); delay(1000); // Fail if B is high or if A or C is low if (getPinValue(PIN_IN_GROUP(g,0)) == 0) failPin(PIN_IN_GROUP(g,0), 4); if (getPinValue(PIN_IN_GROUP(g,1)) == 1) failPin(PIN_IN_GROUP(g,1), 4); if (getPinValue(PIN_IN_GROUP(g,2)) == 0) failPin(PIN_IN_GROUP(g,2), 4); if (g == 10 && getPinValue(PIN_IN_GROUP(g,4)) == 0) failPin(PIN_IN_GROUP(g,4), 4); setPinState(PIN_IN_GROUP(g,3), INPUT); // Test the bonus G10P1 pin if (g == 10) { // Set the bonus G10P1 pin as output low setPinState(PIN_IN_GROUP(g,4), OUTPUT); setPinValue (PIN_IN_GROUP(g,4), 0); delay(1000); // Fail if A or C is high or if B or D is low if (getPinValue(PIN_IN_GROUP(g,0)) == 1) failPin(PIN_IN_GROUP(g,0), 4); if (getPinValue(PIN_IN_GROUP(g,1)) == 0) failPin(PIN_IN_GROUP(g,1), 4); if (getPinValue(PIN_IN_GROUP(g,2)) == 1) failPin(PIN_IN_GROUP(g,2), 4); if (getPinValue(PIN_IN_GROUP(g,3)) == 0) failPin(PIN_IN_GROUP(g,3), 4); setPinState(PIN_IN_GROUP(g,4), INPUT); } } PMD1bits.AD1MD = 0; PMD3bits.AD2MD = 0; }