Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

Arc

28. September 2012

Bei dieser Aufgabe habe ich die physikalische Biegung digital nachgebildet und daraus eine grafische Ausgabe generiert. Die Helligkeit des Striches wird über ein Helligkeitssensor gesteuert. Wird der Sensor mit der Hand vom Licht abgeschirmt wird der gezeichnete Strich dunkler. Über eine LED-Anzeige wird der aktuelle Helligkeitswert angezeigt.
#define LATCH_PIN 8 //Pin zu ST_CP vom 74HC595
#define CLOCK_PIN 12 //Pin zu SH_CP vom 74HC595
#define DATA_PIN 11 //Pin zu DS vom 74HC595
#define LED_9 6
#define LED_10 7
#define TASTER_PLUS 2
#define TASTER_MINUS 3
#define BRIGHTNESS A0
#define PRESSURE A1</code>

int lastButtonState[] = {1,1};
long lastDebounceTime = 0; // Die letzte Zeit als der Taster gedrückt wurde
long timeSinceWait = 0;
long debounceDelay = 20; // Die Verzögerung des Tasters
int counter = 0;

boolean buttonPlusPressed = false;
boolean buttonMinusPressed = false;
boolean wait = false;
boolean press = false;
boolean lookForWait = false;

void setup()
{
pinMode(TASTER_PLUS, INPUT);
digitalWrite(TASTER_PLUS, HIGH);
pinMode(TASTER_MINUS, INPUT);
digitalWrite(TASTER_MINUS, HIGH);

pinMode(LATCH_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(DATA_PIN, OUTPUT);
pinMode(LED_9, OUTPUT);
pinMode(LED_10, OUTPUT);

Serial.begin(9600);
}

void loop()
{
if(digitalRead(TASTER_PLUS) == LOW &amp;&amp; buttonPlusPressed == false)
{
buttonPlusPressed = true;
lastDebounceTime = millis();
timeSinceWait = millis();
}

if(digitalRead(TASTER_MINUS) == LOW &amp;&amp; buttonMinusPressed == false)
{
buttonMinusPressed = true;
lastDebounceTime = millis();
timeSinceWait = millis();
}

if(millis()-lastDebounceTime &gt; debounceDelay &amp;&amp; buttonPlusPressed == true &amp;&amp; wait == false || millis()-lastDebounceTime &gt; debounceDelay &amp;&amp; buttonMinusPressed == true &amp;&amp; wait == false)
{
// AKtion
Serial.println("HERE");
lookForWait = true;
if(buttonMinusPressed &amp;&amp; counter &lt; 15 ){ counter++; } if(buttonPlusPressed &amp;&amp; counter &gt; 0){
counter--;
}

// Serial.print("counter: ");
// Serial.println(counter);
// lastDebounceTime = millis();
wait = true;

if(press){
wait = false;
}
}

counter = map(analogRead(BRIGHTNESS), 50, 400, 0,15);
// counter = map(analogRead(PRESSURE), 0, 255, 0, 15);

Serial.print(analogRead(PRESSURE));
Serial.print(",");
Serial.print(analogRead(BRIGHTNESS));
Serial.print(",");
Serial.println();

if(millis()-timeSinceWait &gt; 1000 &amp;&amp; lookForWait){
wait = false;
press = true;
}

registerWrite(counter, HIGH);

if(digitalRead(TASTER_PLUS) == HIGH &amp;&amp; buttonPlusPressed)
{
buttonPlusPressed = false;
wait = false;
press = false;
lookForWait = false;
// Serial.println("FALSE");
}

if(digitalRead(TASTER_MINUS) == HIGH &amp;&amp; buttonMinusPressed)
{
buttonMinusPressed = false;
wait = false;
press = false;
lookForWait = false;
}
}

void registerWrite(int _whichPin, int _whichState)
{

byte bitsToSend1 = 0; // Dieses Byte hat acht Bits also: 00000000
byte bitsToSend2 = 0;

digitalWrite(LATCH_PIN, LOW);
digitalWrite(LED_9, LOW);
digitalWrite(LED_10, LOW);

if(_whichPin =8)
{
bitWrite(bitsToSend1, _whichPin-8, _whichState);
}
/* Serial.println(_whichPin);
Serial.print(bitsToSend1, BIN);
Serial.print(" ");
Serial.print(bitsToSend2, BIN);
Serial.println();*/
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, bitsToSend1);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, bitsToSend2);

//shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, bitsToSend2);
/*
if(_whichPin &lt; 8){ bitWrite(bitsToSend1, _whichPin, _whichState); // Hier wird das entsprechende Bit im Byte gesetzt (z.B. 00100000) shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, bitsToSend1); shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0); } if(_whichPin &gt;= 8){
bitWrite(bitsToSend2, _whichPin, _whichState); // Hier wird das entsprechende Bit im Byte gesetzt (z.B. 00100000)
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, bitsToSend2);
}
*/
digitalWrite(LATCH_PIN, HIGH);

}

<code>
import processing.serial.*; // Import the Processing Serial Library for communicating with arduino
Serial myPort; // The used Serial Port</code>

int firstValue, secondValue; // fourthValue, fifthValue, ... // add more if needed
float oldValue = 0;
float bend = 0;
float bgFill = 0;

void setup()
{
size(700, 700);
myPort = new Serial(this, Serial.list()[2], 9600); // Open a new port and connect with Arduino at 9600 baud
println(Serial.list());
smooth();
background(#ffffff);
frameRate(60);
}

void draw()
{

if (keyPressed) {
if (key == 's' || key == 'S') {
save("printScreen" + millis() + ".tif");
}
}

bgFill = map(secondValue, 90, 400, 0, 200);
fill(220, 0);
rect(0,0,700,700);

println(firstValue);
println(secondValue);

if(firstValue &gt; 555){
bend = map(firstValue, 555, 820, 0, 350);
}
if(firstValue &lt; 555){ bend = map(firstValue, 510, 555, 0, -350); } // int bend = firstValue; bend = 0.4*oldValue + 0.6*bend; oldValue = bend; println(bend); pushMatrix(); translate(width/2, height/2); int rotation = millis(); rotate(rotation); fill(255); rect(-350, -280, 700,10); rect(-350,270, 700, 10); noFill(); // stroke(255, 102, 0); // rotate(degrees(millis()/1500)); line(0, -275, bend, -275); line(bend, 275, 0, 275); stroke(0, bgFill); bezier(0, -250, bend, -250, bend, 250, 0, 250); popMatrix(); fill(255); stroke(255); rect(600, 475, 100, 50); fill(0); text(bend, 600, 500); } void serialEvent(Serial myPort) // Is called everytime there is new data to read { if (myPort.available() &gt; 0)
{
String completeString = myPort.readStringUntil(10); // Read the Serial port until there is a linefeed/carriage return
if (completeString != null) // If there is valid data insode the String
{
trim(completeString); // Remove whitespace characters at the beginning and end of the string
String seperateValues[] = split(completeString, ","); // Split the string everytime a delimiter is received
firstValue = int(seperateValues[0]);
secondValue = int(seperateValues[1]);
}
}
}