Ok. I have to program the use of the DangerShield of ZachHoeken. The Images are just pictures of the DangerShield and some Leds on and so on.
I want to read the value of the first Slider. At first it didn't want to work, now Processing prints me the only the first value all the time and even though the slider is at its fullest position (has a value of 1023) it only sends 255 ...
Here is the processing Code: (by the way, I'm writing code with Eclipse, so don't wonder because of some differences

)
public class DangerShield extends PApplet {
//import class to set up serial connection with wiring board
Serial port;
String test;
PImage Shield;
PImage[] LED1= new PImage[2];
int ld1 = 0;
PImage[] LED2=new PImage[2];
int ld2 = 0;
PImage[] SegLED = new PImage[10];
int i = 0;
int j = 0;
int[] stand = {0,0,0,0,0,0,0};
public void setup()
{
background(255);
Shield=loadImage("DShield.jpg");
LED1[0]=loadImage("LED1aus.png");
LED1[1]=loadImage("LED1an.png");
LED2[0]=loadImage("LED2aus.png");
LED2[1]=loadImage("LED2an.png");
for(int j = 0; j<10;j++)
SegLED[j]=loadImage(""+j+".png");
size(900,375);
println(Serial.list());
port = new Serial(this,Serial.list()[0],9600);
image(Shield,200,0);
}
int slider1 = 0;
public void draw()
{
fLED1();
fLED2();
fSegLed();
portwrite();
if(port.available()>0)
{
slider1 = port.read();
println(slider1);
}
//println("Mausx: " + mouseX + "\tMausy: "+mouseY);
fill(255);
rect(0,0,200,375);
rect(700,0,200,375);
texte();
}
public void fLED1() //Koordinaten: X von 558-580; Y von 163-191
{
boolean over = false;
if(mouseX>=558 && mouseX<=580 && mouseY>=162 && mouseY <=191)
over = true;
//println(over);
if(over==true )
{
i = 1;
image(LED1[stand[i]],555,160); // turns LED on
ld1 = stand[i];
}
}
public void fLED2() //Koordinaten: X von 550-576; Y von 134-167
{
boolean over = false;
if(mouseX>=550 && mouseX<=576 && mouseY>=134 && mouseY <=162)
over = true;
//print(over);
if(over==true )
{
i = 2;
image(LED2[stand[i]],553,133); //turns LED on
ld2 = stand[i];
}
}
public void fSegLed() //7 Segment-LED
{
boolean over1 = false; // Maus über Button1 X: 380-401 Y:250-270
boolean over2 = false; // Maus über Button2 X: 446-467 Y:250-270
boolean over3 = false; // Maus über Button3 X: 508-531 Y:250-270
if(mouseX>=380 && mouseX<=401 && mouseY >=250 && mouseY <=270)
{
over1 = true;
i = 3;
if(mousePressed)
{
delay(150);
j++;
}
if(j>9)
j = 0;
}
if(mouseX>=446 && mouseX <= 467 && mouseY >=250 && mouseY <=270)
{
over2 = true;
i = 3;
if(mousePressed)
{
delay(150);
j--;
}
if(j<0)
{
j=9;
}
}
image(SegLED[j],301,212);
}
public void portwrite()
{
if(ld1 == 1)
port.write('A');
if(ld1 == 0)
port.write('B');
if(ld2 == 1)
port.write('C');
if(ld2 == 0)
port.write('D');
port.write(j);
}
public void texte()
{
fill(0);
line(110,20,110,355);
text("Wert von Slider1:",2,60);
}
public void mouseReleased()
{
stand[i] = 1 - stand[i];
}
}
and the Arduino Code:
#include <WProgram.h>
#include <stdio.h>
#define LatchPin 8
#define ClockPin 12
#define DataPin 13
byte chardata[] =
{
B00111111, //0
B00000110, //1
B01011011, //2
B01001111, //3
B01100110, //4
B01101101, //5
B01111101, //6
B00000111, //7
B01111111, //8
B01101111 //9
};
extern "C" void __cxa_pure_virtual()
{
cli();
for (;;);
}
int i = 0;
int led;
int oldled;
char ascii[6];
void setup() {
Serial.begin(9600);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(LatchPin, OUTPUT);
pinMode(ClockPin, OUTPUT);
pinMode(DataPin, OUTPUT);
pinMode(A0, INPUT);
digitalWrite(LatchPin, LOW);
shiftOut(DataPin, ClockPin, MSBFIRST, 0);
digitalWrite(LatchPin,HIGH);
}
void loop()
{
int slider1 = analogRead(A0);
Serial.write(slider1);
if(Serial.available())
{
led = Serial.read();
if ( led == 'A')
digitalWrite(6, HIGH);
if (led == 'B')
digitalWrite(6, LOW);
if (led == 'C')
digitalWrite(5,HIGH);
if (led == 'D')
digitalWrite(5, LOW);
if(led!=oldled)
{
digitalWrite(LatchPin, LOW);
shiftOut(DataPin, ClockPin, MSBFIRST, chardata[led]);
digitalWrite(LatchPin,HIGH);
oldled = led;
}
}
}
int main (void)
{
init ();
setup();
for(;;)
loop();
}