Honeycomb surface and programming of sensors and motors

照片Programming for servo infrared, servo sensor and wheels movement

Servo Infrared

const int sensorPin = 0;
float distance;
void setup() {
  Serial.begin(9600);
}

void loop () {
  distance = 0;
  for (int i = 0; i < 20; i++) {
    distance += analogRead(sensorPin);
    delay(10);
  }
  distance = distance / 20;
  
  Serial.print(distance);
  Serial.println();
}

Servo sensor

#include  
Servo servo1;
const int sensorPin = 0;
int lightLevel, high = 0, low = 1023;

void setup() { 
   //Serial.begin(9600);
   servo1.attach(9);// Enable control of a servo on pin 9:
}

void loop() { 
  int lightLevel;    // Input value from the analog pin.
  int servoposition;   // Output value to the servo.
  lightLevel = analogRead(sensorPin);
  servoposition = map(lightLevel, 600, 900, 0, 180);
  servoposition = constrain(servoposition, 0, 180);                                                                                                                                                                                                                                                        
  servo1.write(servoposition);
  //autoTune();
  manualTune(); 
  delay(20);
}

void manualTune() {
  lightLevel = map(lightLevel, 0, 1023, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
} 

void autoTune() {
  if (lightLevel < low) {     low = lightLevel;   }   if (lightLevel > high) {
    high = lightLevel;
  }

  lightLevel = map(lightLevel, low+30, high-30, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);

}

Wheels movement

#include  
Servo servo1;
Servo servo2;
const int sensor = 0;

int leftZero = 96;
int rightZero = 93;

void setup() 
{ 
  // Use the serial monitor window to help debug our sketch:

  Serial.begin(9600);

  // Enable control of a servo on pin 9:

  servo1.attach(9);
  servo2.attach(10);
} 
void loop() 
{ 
  int sensor;  
  int leftspeed;
  sensor = analogRead(sensor);
  leftspeed = map(sensor, 100, 800, 0, 180);
  leftspeed = constrain(leftspeed, 0, 180);
  servo1.write(leftspeed);

  int rightspeed = rightZero - (leftspeed - leftZero);
  servo2.write(rightspeed);
}

Honeycomb surface by AI

Honeycomb(vertical)v2(2)

Honeycomb(vertical)v2(1)Honeycomb(side2)v2

CAUTION. We almost ruined the workshop downstairs by laser-cutting polycarbonate material because we thought it was perspex when we bought it. : p

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s