Commit 5a0ff26b authored by Patrick Engelbrecht Sørensen's avatar Patrick Engelbrecht Sørensen
Browse files

Delete color_slave_v3.ino

parent 94528a3f
#include <SPI.h>
#include <Wire.h>
#define S0 9
#define S1 8
#define S2 11
#define S3 12
#define sensorOut 10
int frequency = 0;
int color = 0;
void setup() {
Wire.begin(8);
Wire.onRequest(requestEvent);
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
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);
}
void loop() {
requestEvent();
delay(500);
}
void requestEvent() {
// Custom Function - readColor()
// Setting red filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int R = frequency;
// Printing the value on the serial monitor
Serial.print("R= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(" ");
delay(50);
// Setting Green filtered photodiodes to be read
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int G = frequency;
// Printing the value on the serial monitor
Serial.print("G= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(" ");
delay(50);
// Setting Blue filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
int B = frequency;
// Printing the value on the serial monitor
Serial.print("B= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.println(" ");
delay(50);
int sensorValue = analogRead(A3);
float voltage = sensorValue * (5.0 / 1024.0);
float I = voltage / 1000;
float VRx = 5 - voltage;
float Rx = VRx / I;
Rx = (5 - voltage) / I;
// print out the value you read:
Serial.print("Resistance:");
Serial.print(Rx);
Serial.println(" Ohms");
/* if (G<400 & G>351 & B<400 & B>351) {
color = 1; //Brown
if (color == 1 && Rx > 600 && Rx < 1500) {
color = 5; // Brown && Attachment greenLED
}
}*/
if (G<8000 & G>351 & B<8000 & B>351) {
color = 2; // Green
if (color == 2 && Rx > 4000 && Rx < 110000) {
color = 6; // Green && Attachment greenLED
}
}
if (G<350 & G>1 & B<350 & B>1) {
color = 3; // Yellow
if (color == 3 && Rx > 1 && Rx < 3999) {
color = 7; // Yellow && Attachment greenLED
}
}
/* if (G<310 & G> & B<209 & B>181) {
color = 4; // Orange
if (color == 4 && Rx > 200 && Rx < 500) {
color = 8; // Orange && Attachment greenLED
}
}*/
/* if (G<23 & G>20 & B<23 & B>20) {
color = 9; // Red
}
if (G<28 & G>24 & B<28 & B>24) {
color = 10; // Blue
}
*/
Wire.write(color); // respond with message of 6 bytes
color = 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment