Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*     Arduino Color Sensing Tutorial
  2.  *      
  3.  *  by Dejan Nedelkovski, www.HowToMechatronics.com
  4.  *  
  5.  */
  6.  
  7. #define S0 8
  8. #define S1 9
  9. #define S2 11
  10. #define S3 10
  11. #define sensorOut 12
  12.  
  13. int frequency = 0;
  14.  
  15.  
  16. void setup() {
  17.   pinMode(S0, OUTPUT);
  18.   pinMode(S1, OUTPUT);
  19.   pinMode(S2, OUTPUT);
  20.   pinMode(S3, OUTPUT);
  21.   pinMode(sensorOut, INPUT);
  22.  
  23.   // Setting frequency-scaling to 20%
  24.   digitalWrite(S0,HIGH);
  25.   digitalWrite(S1,LOW);
  26.  
  27.   Serial.begin(9600);
  28. }
  29. void loop() {
  30.   // Setting red filtered photodiodes to be read
  31.   digitalWrite(S2,LOW);
  32.   digitalWrite(S3,LOW);
  33.  
  34.   // Reading the output frequency
  35.   frequency = pulseIn(sensorOut, LOW);
  36.  
  37.   // Printing the value on the serial monitor
  38.   Serial.print("Red= ");//printing name
  39.   Serial.print(frequency);//printing RED color frequency
  40.   Serial.print("  ");
  41.  
  42.   // Setting Green filtered photodiodes to be read
  43.   digitalWrite(S2,HIGH);
  44.   digitalWrite(S3,HIGH);
  45.  
  46.   // Reading the output frequency
  47.   frequency = pulseIn(sensorOut, LOW);
  48.  
  49.   // Printing the value on the serial monitor
  50.   Serial.print("Green= ");//printing name
  51.   Serial.print(frequency);//printing RED color frequency
  52.   Serial.print("  ");
  53.  
  54.   // Setting Blue filtered photodiodes to be read
  55.   digitalWrite(S2,LOW);
  56.   digitalWrite(S3,HIGH);
  57.  
  58.   // Reading the output frequency
  59.   frequency = pulseIn(sensorOut, LOW);
  60.  
  61.   // Printing the value on the serial monitor
  62.   Serial.print("Blue= ");//printing name
  63.   Serial.print(frequency);//printing RED color frequency
  64.   Serial.println("  ");
  65.   delay(100);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement