Guest User

Untitled

a guest
Mar 20th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. int sensorPin = 0; // select the input pin for the potentiometer
  2. int sensorValue = 0; // variable to store the value coming from the sensor
  3.  
  4. #ifndef cbi
  5. #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
  6. #endif
  7. #ifndef sbi
  8. #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
  9. #endif
  10.  
  11. void setup()
  12. {
  13. Serial.begin(9600);
  14. pinMode(6, OUTPUT);
  15. sbi(ADCSRA,ADPS2);
  16. cbi(ADCSRA,ADPS1);
  17. cbi(ADCSRA,ADPS0);
  18. }
  19.  
  20. void loop() {
  21. // read the value from the sensor:
  22. if(analogRead(sensorPin) > 400)
  23. {
  24. PORTD = 0b0000000;
  25. delay_x(5);
  26. digitalWrite(6, HIGH);
  27. }
  28. }
  29.  
  30. void delay_x(uint32_t millis_delay)
  31. {
  32. uint16_t micros_now = (uint16_t)micros();
  33.  
  34. while (millis_delay > 0) {
  35. if (((uint16_t)micros() - micros_now) >= 1000) {
  36. millis_delay--;
  37. micros_now += 1000;
  38. }
  39. }
  40. }
Add Comment
Please, Sign In to add comment