Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int red = 10;
  2. int blue = 9;
  3. int green = 11;
  4. int xposPin = A0;
  5. int yposPin = A1;
  6. int zposPin = A2;
  7.  
  8. void setup() {
  9.   // initialize serial communication at 9600 bits per second:
  10.   Serial.begin(9600);
  11.  pinMode(red,OUTPUT);
  12. pinMode(blue,OUTPUT);
  13. pinMode(green,OUTPUT);
  14. }
  15.  
  16. // the loop routine runs over and over again forever:
  17. void loop() {
  18.   // read the input on analog pin 0:
  19.   int valueXpos = analogRead(xposPin);
  20.   int valueYpos = analogRead(yposPin);
  21.   int valueZpos = analogRead(zposPin);
  22.   // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  23.   float voltageX = valueXpos * (5.0 / 1023.0);
  24.   float voltagey = valueYpos * (5.0 / 1023.0);
  25.   float voltagez = valueZpos * (5.0 / 1023.0);
  26.   // print out the value you read::
  27.   Serial.print("Position X = ");
  28.   Serial.print(voltageX);
  29.   Serial.print(";   Position Y = ");
  30.   Serial.print(voltagey);
  31.   Serial.print(";   Position Z = ");
  32.   Serial.print(voltagez);
  33.   Serial.println("");
  34.   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))
  35.   {
  36.   analogWrite(red,0);
  37.   analogWrite(green,0);
  38.   analogWrite(blue,0);
  39.   }
  40.   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)))
  41.   {
  42.   analogWrite(red,0);
  43.   analogWrite(green,255);
  44.   analogWrite(blue,0);
  45.   }
  46.   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)))
  47.   {
  48.   analogWrite(red,0);
  49.   analogWrite(green,0);
  50.   analogWrite(blue,255);
  51.   }
  52.   else
  53.   {
  54.    analogWrite(red,255);
  55.   analogWrite(green,0);
  56.   analogWrite(blue,0);  
  57.   }
  58.  
  59.   delay(10);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement