Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int red = 10;
- int blue = 9;
- int green = 11;
- int xposPin = A0;
- int yposPin = A1;
- int zposPin = A2;
- void setup() {
- // initialize serial communication at 9600 bits per second:
- Serial.begin(9600);
- pinMode(red,OUTPUT);
- pinMode(blue,OUTPUT);
- pinMode(green,OUTPUT);
- }
- // the loop routine runs over and over again forever:
- void loop() {
- // read the input on analog pin 0:
- int valueXpos = analogRead(xposPin);
- int valueYpos = analogRead(yposPin);
- int valueZpos = analogRead(zposPin);
- // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
- float voltageX = valueXpos * (5.0 / 1023.0);
- float voltagey = valueYpos * (5.0 / 1023.0);
- float voltagez = valueZpos * (5.0 / 1023.0);
- // print out the value you read::
- Serial.print("Position X = ");
- Serial.print(voltageX);
- Serial.print("; Position Y = ");
- Serial.print(voltagey);
- Serial.print("; Position Z = ");
- Serial.print(voltagez);
- Serial.println("");
- if((voltageX <= 1.75 && voltageX >=1.65 )&&( voltagey <= 1.70 && voltagey >=1.55 )&& (voltagez <= 2.05 && voltagez >=1.95)||(voltageX <= 1.65 && voltageX >=1.50 )&&( voltagey <= 1.70 && voltagey >=1.55 )&& (voltagez <= 1.45 && voltagez >=1.30))
- {
- analogWrite(red,0);
- analogWrite(green,0);
- analogWrite(blue,0);
- }
- else if(((voltageX <= 1.68 && voltageX >=1.60) && (voltagey <= 2.00 && voltagey >=1.90) && (voltagez <= 1.75 && voltagez >=1.60))||((voltageX <= 1.70 && voltageX >=1.60) &&( voltagey <= 1.35 && voltagey >=1.25) && (voltagez <= 1.75 && voltagez >=1.60)))
- {
- analogWrite(red,0);
- analogWrite(green,255);
- analogWrite(blue,0);
- }
- else if(((voltageX <= 1.92 && voltageX >=1.83) &&( voltagey <= 1.65 && voltagey >=1.55) && (voltagez <= 1.75 && voltagez >=1.65))||((voltageX <= 1.45 && voltageX >=1.35) &&( voltagey <= 1.68 && voltagey >=1.56) && (voltagez <= 1.75 && voltagez >=1.65)))
- {
- analogWrite(red,0);
- analogWrite(green,0);
- analogWrite(blue,255);
- }
- else
- {
- analogWrite(red,255);
- analogWrite(green,0);
- analogWrite(blue,0);
- }
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement