Advertisement
Electgpl

ARDUINO - Demo Board

Oct 6th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.28 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo myservo;
  3. #define GREEN 9
  4. #define BLUE 10
  5. #define RED 11
  6. #define delayTimeRGB 20
  7. #define BUZZER 6
  8. #define BOTON 2
  9. #define LDR A0
  10. #define TEMP A1
  11. #define POTE A2
  12. #define SERVO 5
  13. #define BLINK 13
  14. void setup() {
  15.     pinMode(BUZZER, OUTPUT);
  16.     pinMode(BOTON, INPUT);
  17.     pinMode(LDR, INPUT);
  18.     pinMode(TEMP, INPUT);
  19.     pinMode(POTE, INPUT);
  20.     pinMode(SERVO, OUTPUT);
  21.     pinMode(GREEN, OUTPUT);
  22.     pinMode(BLUE, OUTPUT);
  23.     pinMode(RED, OUTPUT);
  24.     Serial.begin(9600);
  25.     myservo.attach(SERVO);
  26. }
  27. void loop() {
  28.     //funcionSERVO();
  29.     funcionRGB();  
  30.     //funcionLDR();
  31.     //funcionPOTE();
  32.     //funcionTEMP();
  33.     //funcionBUZZER();
  34. }
  35. void funcionRGB() {
  36.     for(int b=0;b<16;b++){
  37.        analogWrite(BLUE, b);
  38.        delay(delayTimeRGB);
  39.     }
  40.     for(int r=16;r>1;r--){
  41.        analogWrite(RED, r);
  42.        delay(delayTimeRGB);
  43.     }
  44.     for(int g=0;g<16;g++){
  45.        analogWrite(GREEN, g);
  46.        delay(delayTimeRGB);
  47.     }
  48.     for(int b=16;b>1;b--){
  49.        analogWrite(BLUE, b);
  50.        delay(delayTimeRGB);
  51.     }      
  52.     for(int r=0;r<16;r++){
  53.        analogWrite(RED, r);
  54.        delay(delayTimeRGB);
  55.     }
  56.     for(int g=16;g>1;g--){
  57.        analogWrite(GREEN, g);
  58.        delay(delayTimeRGB);
  59.     }
  60. }
  61. void funcionPOTE() {
  62.     int sensorValue = analogRead(POTE);
  63.     Serial.println("POTENCIOMETRO");
  64.     Serial.print("ADC: ");
  65.     Serial.println(sensorValue);
  66.     digitalWrite(BLINK, HIGH);
  67.     delay(100);
  68.     digitalWrite(BLINK, LOW);
  69.     delay(1000);
  70. }
  71. void funcionLDR() {
  72.     int sensorValue = analogRead(LDR);
  73.     Serial.println("LDR");
  74.     Serial.print("LUX: ");
  75.     Serial.println(map(sensorValue,0,1023,20,1000));
  76.     digitalWrite(BLINK, HIGH);
  77.     delay(100);
  78.     digitalWrite(BLINK, LOW);
  79.     delay(1000);
  80. }
  81. void funcionTEMP() {
  82.     int sensorValue = analogRead(TEMP);
  83.     Serial.println("TEMPERATURA");
  84.     Serial.print("C: ");
  85.     Serial.println(sensorValue*0.41);
  86.     digitalWrite(BLINK, HIGH);
  87.     delay(100);
  88.     digitalWrite(BLINK, LOW);
  89.     delay(1000);
  90. }
  91. void funcionSERVO() {
  92.     for (int pos = 0; pos <= 180; pos += 1) {
  93.         myservo.write(pos);
  94.         delay(15);
  95.     }
  96.     for (int pos = 180; pos >= 0; pos -= 1) {
  97.         myservo.write(pos);
  98.         delay(15);
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement