2015年4月27日星期一

Week 6. Finish the chip and testing code (during the non-teach week)

During the non-teach week, I finally combine these functions together.But I think the most important part is the coding to the Unreal Engine 4.

Here is the image for the chip.

Image 1


Image 2

And after putting everything together, we need to working on the coding.Because I do the combine by myself, so Elliott working on the coding( because he didn't get another kits before the non-teach week).So he just send me the code to me then I upload the coding into arduino softeware and connecting the chip to test it works or not.

After few tests, We just get a result that is: dont use the flex sensor for our project.Because we just tested out that flex sensor is not very accurate for the driving machine project. 

How could we test the accurate?

In the Arduino software clicked on tools => serialmoitor, then a second window will came up, and in this window it shows the value changing when I turning the potentiometer or banding the flex sensor.

The value is between 0 to 255. and the values of potentiometer are really accurate and working well, but the values of flex sensor are keep changing.( can't hold the value )

New decision:

Trying to just 2 potentiometers for the project and make them working.


Testing Coding:


1. Use potentiometer to change the brightness


int ledPin = 9; //pin that LED is attached to
int brightness = 0;
int analogValue = 0; // value read from the pot
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
analogValue = analogRead(A0); //read the pot value
brightness = analogValue/4; //divided by 4 to fit in a byte
analogWrite(ledPin, brightness); // PWM the LED with the brightness value
Serial.println(brightness); //print the brightness value back to the serial monitor
}




2. Use potentiometer to change the flashing frequency of the led light


int ledPin = 9; //pin that LED is attached to
int brightness = 0;
int analogValue = 0; // value read from the pot
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
analogValue = analogRead(A0); //read the pot value
brightness = analogValue/4; //divided by 4 to fit in a byte
analogWrite(ledPin, brightness); // PWM the LED with the brightness value
Serial.println(brightness); //print the brightness value back to the serial monitor
}  



3. Use flex sensor to change the flashing frequency of the led light



int ledPin = 9; //pin that LED is attached to
int brightness = 0;
int analogValue = 0; // value read from the pot
int sensorValue = 0;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop() {
analogValue = analogRead(A0); //read the pot value
brightness = analogValue/4; //divided by 4 to fit in a byte
analogWrite(ledPin, brightness); // PWM the LED with the brightness value
Serial.println(brightness); //print the brightness value back to the serial monitor
  // read the value from the sensor:
  sensorValue = analogRead(A1);
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);
  // turn the ledPin off:
  digitalWrite(ledPin, LOW);
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);
}



没有评论:

发表评论