Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int sensorPin = 0; // select the input pin for the potentiometer
- int sensorValue = 0; // variable to store the value coming from the sensor
- #ifndef cbi
- #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
- #endif
- #ifndef sbi
- #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
- #endif
- void setup()
- {
- Serial.begin(9600);
- pinMode(6, OUTPUT);
- sbi(ADCSRA,ADPS2);
- cbi(ADCSRA,ADPS1);
- cbi(ADCSRA,ADPS0);
- }
- void loop() {
- // read the value from the sensor:
- if(analogRead(sensorPin) > 400)
- {
- PORTD = 0b0000000;
- delay_x(5);
- digitalWrite(6, HIGH);
- }
- }
- void delay_x(uint32_t millis_delay)
- {
- uint16_t micros_now = (uint16_t)micros();
- while (millis_delay > 0) {
- if (((uint16_t)micros() - micros_now) >= 1000) {
- millis_delay--;
- micros_now += 1000;
- }
- }
- }
Add Comment
Please, Sign In to add comment