Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Arduino Color Sensing Tutorial
- *
- * by Dejan Nedelkovski, www.HowToMechatronics.com
- *
- */
- #define S0 8
- #define S1 9
- #define S2 11
- #define S3 10
- #define sensorOut 12
- int frequency = 0;
- void setup() {
- pinMode(S0, OUTPUT);
- pinMode(S1, OUTPUT);
- pinMode(S2, OUTPUT);
- pinMode(S3, OUTPUT);
- pinMode(sensorOut, INPUT);
- // Setting frequency-scaling to 20%
- digitalWrite(S0,HIGH);
- digitalWrite(S1,LOW);
- Serial.begin(9600);
- }
- void loop() {
- // Setting red filtered photodiodes to be read
- digitalWrite(S2,LOW);
- digitalWrite(S3,LOW);
- // Reading the output frequency
- frequency = pulseIn(sensorOut, LOW);
- // Printing the value on the serial monitor
- Serial.print("Red= ");//printing name
- Serial.print(frequency);//printing RED color frequency
- Serial.print(" ");
- // Setting Green filtered photodiodes to be read
- digitalWrite(S2,HIGH);
- digitalWrite(S3,HIGH);
- // Reading the output frequency
- frequency = pulseIn(sensorOut, LOW);
- // Printing the value on the serial monitor
- Serial.print("Green= ");//printing name
- Serial.print(frequency);//printing RED color frequency
- Serial.print(" ");
- // Setting Blue filtered photodiodes to be read
- digitalWrite(S2,LOW);
- digitalWrite(S3,HIGH);
- // Reading the output frequency
- frequency = pulseIn(sensorOut, LOW);
- // Printing the value on the serial monitor
- Serial.print("Blue= ");//printing name
- Serial.print(frequency);//printing RED color frequency
- Serial.println(" ");
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement