task main() { // The data to be written: 0x3F = 111111 binary, // makes all digital ports outputs. HTPBsetupIO(HTPB, 0x3F); while(true) { // Switch off LED on port B0 HTPBwriteIO(HTPB, 0x00); sleep(30); wolight = HTPBreadADC(HTPB, 0, 10); // Switch on LED on port B0 HTPBwriteIO(HTPB, 0x01); sleep(30); wlight = HTPBreadADC(HTPB, 0, 10); // Calculate the difference lightdelta = wlight - wolight; eraseDisplay(); displayTextLine(1, "%4d", wlight); displayTextLine(2, "%4d", wolight); displayTextLine(3, "%4d", lightdelta); sleep(30); } }
task main() { int _chVal = 0; nxtDisplayCenteredTextLine(0, "HiTechnic"); nxtDisplayCenteredBigTextLine(1, "Proto"); nxtDisplayCenteredTextLine(3, "Test 1"); nxtDisplayCenteredTextLine(5, "Connect HTPB"); nxtDisplayCenteredTextLine(6, "to S1"); wait1Msec(2000); // Setup all the digital IO ports as outputs (0xFF) if (!HTPBsetupIO(HTPB, 0xFF)) { nxtDisplayTextLine(4, "ERROR!!"); wait1Msec(2000); StopAllTasks(); } while(true) { eraseDisplay(); // get the value for ADC channel 0, we want a 10 bit answer _chVal = HTPBreadADC(HTPB, 0, 10); nxtDisplayTextLine(4, "A0: %d", _chVal); // if _chVal is more than 512, turn on the LED, otherwise turn it off. if (_chVal > 512) { if (!HTPBwriteIO(HTPB, 0xFF)) nxtDisplayTextLine(5, "ERR WRITE"); } else { if (!HTPBwriteIO(HTPB, 0x00)) nxtDisplayTextLine(5, "ERR WRITE"); } wait1Msec(100); } }
task main() { // Local variables int inputdata; ubyte outputdata; // The data to be written: 0x3F = 111111 binary, // makes all digital ports outputs. HTPBsetupIO(HTPB, 0x3F); while(true) { // Read a 10bit wide analogue value from A0 inputdata = HTPBreadADC(HTPB, 0, 10); eraseDisplay(); nxtDisplayTextLine(1, "%d", inputdata); // Depending on the input voltage on A0, // turn on the corresponding LED. outputdata = 0x01; if (inputdata > 31) outputdata = 0x02; if (inputdata > 63) outputdata = 0x04; if (inputdata > 127) outputdata = 0x08; if (inputdata > 255) outputdata = 0x10; if (inputdata > 511) outputdata = 0x20; HTPBwriteIO(HTPB, outputdata); wait1Msec(50); } }
task main() { int _chVal = 0; nxtDisplayCenteredTextLine(0, "HiTechnic"); nxtDisplayCenteredBigTextLine(1, "Proto"); nxtDisplayCenteredTextLine(3, "Test 1"); nxtDisplayCenteredTextLine(5, "Connect SMUX to"); nxtDisplayCenteredTextLine(6, "S1 and HTPB to"); nxtDisplayCenteredTextLine(7, "SMUX Port 1"); wait1Msec(2000); // Before using the SMUX, you need to initialise the driver HTSMUXinit(); // Tell the SMUX to scan its ports for connected sensors HTSMUXscanPorts(HTSMUX); PlaySound(soundBeepBeep); while(bSoundActive); eraseDisplay(); while(true) { eraseDisplay(); // get the value for ADC channel 0, we want a 10 bit answer _chVal = HTPBreadADC(msensor_S1_1, 0, 10); nxtDisplayTextLine(4, "A0: %d", _chVal); wait1Msec(10); } }
task main() { int _chVal = 0; nxtDisplayCenteredTextLine(0, "HiTechnic"); nxtDisplayCenteredBigTextLine(1, "Proto"); nxtDisplayCenteredTextLine(3, "Test 1"); nxtDisplayCenteredTextLine(5, "Connect SMUX to"); nxtDisplayCenteredTextLine(6, "S1 and HTPB to"); nxtDisplayCenteredTextLine(7, "SMUX Port 1"); wait1Msec(2000); PlaySound(soundBeepBeep); while(bSoundActive) EndTimeSlice(); eraseDisplay(); while(true) { eraseDisplay(); // get the value for ADC channel 0, we want a 10 bit answer _chVal = HTPBreadADC(HTPB, 0, 10); nxtDisplayTextLine(4, "A0: %d", _chVal); wait1Msec(10); } }
task main() { int AnalogPins = 0; // analog input byte DigitalPins = 0; // all digital inputs int RawReading = 0; nxtDisplayCenteredTextLine(0, "HiTechnic"); nxtDisplayCenteredBigTextLine(1, "Proto"); nxtDisplayCenteredTextLine(3, "Test 1"); nxtDisplayCenteredTextLine(5, "Connect HTPB"); nxtDisplayCenteredTextLine(6, "to S1"); wait1Msec(2000); // Setup all the digital IO ports as outputs (0x10) 010000 pin B4 = output, others are inputs. if (!HTPBsetupIO(HTPB, 0x10)) { nxtDisplayTextLine(4, "ERROR!!"); wait1Msec(2000); StopAllTasks(); } while(true) { //reset the reading value RawReading = 0; //clear the NXT eraseDisplay(); //get the analog values for(int i = 0; i < 5; i++) { AnalogPins = HTPBreadADC(HTPB, i, 10); nxtDisplayTextLine(i, "A0: %d", AnalogPins); if (AnalogPins > 512) { RawReading += (1 << (4 + (4 - i)); } } //get the digital values DigitalPins = HTPBreadIO(HTPB, 0x3F); nxtDisplayTextLine(5, "D: 0x%x", DigitalPins); RawReading += (DigitalPins&0x01) << 3; RawReading += (DigitalPins&0x02) << 1; RawReading += (DigitalPins&0x04) >> 1; RawReading += (DigitalPins&0x08) >> 3; nxtDisplayBigTextLine(6, "%d", RawReadingToDegrees(RawReading)); //let other threads do shit wait1Msec(50); }
task main() { // Local variables int inputdata; while(true) { // Read a 10bit wide analogue value from A0 inputdata = HTPBreadADC(HTPB, 0, 10); eraseDisplay(); nxtDisplayTextLine(1, "%d", inputdata); wait1Msec(50); } }
task main() { // The data to be written: 0x3F = 111111 binary, // makes B4 digital port an output. HTPBsetupIO(HTPB, 0x3F); while(true) { // Read the value from the temp sensor inputdata = HTPBreadADC(HTPB, 0, 10); // Convert to an actual temperature temperature = ((inputdata - 186) * 32 / 99); eraseDisplay(); nxtDisplayTextLine(1, "%d", temperature); // If we're above 28 degrees, switch on the LED if(temperature > THRESHOLD) { HTPBwriteIO(HTPB, 0x10); } else { HTPBwriteIO(HTPB, 0x00); } wait1Msec(50); } }
task main() { // Local variables int inputdata; // The data to be written: 0x3F = 111111 binary, // makes all digital ports outputs. HTPBsetupIO(HTPB, 0x3F); while(true) { // Read a 10bit wide analogue value from A0 inputdata = HTPBreadADC(HTPB, 0, 10); eraseDisplay(); nxtDisplayTextLine(1, "%d", inputdata); // If A0 is less than 50% of the max value // turn off the LED, otherwise switch it on if(inputdata < 512) HTPBwriteIO(HTPB, 0x00); else HTPBwriteIO(HTPB, 0x01); wait1Msec(50); } }
task main() { int _chVal = 0; // analog input byte inputs = 0; // all digital inputs int value = 0; int touchValue = 0; int touchValue2 = 0; nxtDisplayCenteredTextLine(0, "HiTechnic"); nxtDisplayCenteredBigTextLine(1, "Proto"); nxtDisplayCenteredTextLine(3, "Test 1"); nxtDisplayCenteredTextLine(5, "Connect HTPB"); nxtDisplayCenteredTextLine(6, "to S1"); wait1Msec(2000); // Setup all the digital IO ports as outputs (0x30) 110000 pins B4/B5 = outputs, others are inputs. if (!HTPBsetupIO(HTPB, 0x30)) { nxtDisplayTextLine(4, "ERROR!!"); wait1Msec(2000); StopAllTasks(); } while(true) { value = 0; eraseDisplay(); // get the value for ADC channel 0, we want a 10 bit answer int j = 0; for(int i=0; i<5; i++) { _chVal = HTPBreadADC(HTPB, j, 10); switch(j) { case 0: nxtDisplayTextLine(0, "A0: %d", _chVal); if(_chVal>512) value+=(1<<8); break; case 1: nxtDisplayTextLine(1, "A1: %d", _chVal); if(_chVal>512) value+=(1<<7); break; case 2: nxtDisplayTextLine(2, "A2: %d", _chVal); if(_chVal>512) value+=(1<<6); break; case 3: nxtDisplayTextLine(3, "A3: %d", _chVal); if(_chVal>512) value+=(1<<5); break; case 4: nxtDisplayTextLine(4, "A4: %d", _chVal); if(_chVal>512) value+=(1<<4); break; } j++; } inputs = HTPBreadIO(HTPB, 0x3F); nxtDisplayTextLine(5, "D: 0x%x", inputs); value+=(inputs&0x01)<<3; value+=(inputs&0x02)<<1; value+=(inputs&0x04)>>1; value+=(inputs&0x08)>>3; nxtDisplayBigTextLine(6, "%d", mapNineBitToDegrees(value)); touchValue = SensorValue[S2]; touchValue2 = SensorValue[S3]; if(touchValue == 1 && touchValue2 == 1) { HTPBwriteIO(HTPB, 0x30); } // turn on B4 and B5 else if(touchValue == 1) { HTPBwriteIO(HTPB, 0x10); } // turn on B4 else if(touchValue2 == 1) { HTPBwriteIO(HTPB, 0x20); } // turn on B5 else { HTPBwriteIO(HTPB, 0x00); } // turn both B4 and B5 off wait1Msec(50); } }