Go Down

Topic: pushing a button makes appear a picture at the computerscreen (Read 2317 times) previous topic - next topic

lkjh

Jun 13, 2011, 01:47 am Last Edit: Jun 13, 2011, 01:25 pm by lkjh Reason: 1
hi everyone!
i hope to get help with that, because i quite confused.

i tried do write a code for letting pictures appear at the computerscreen to the activations of pushbuttons. there are 7 pushbottons and each one has its dedicated picture.

but i have several problems:

i dont know how to define the output correctly?

as well i cant say whats the right command for that kind of coding, is it serial.write or serial.print or digital.write... or what else..?

also i dont know if arduino or processing are able to project pictures, so i was looking for an converter and found that:
http://www.henningkarlsen.com/electronics/t_imageconverter565.php
but its not really working...

im a real beginner!!! bloody beginner! i didnt have problems to modificate the examples but this is beyond me!!

please, could somebody help me out?
have to finish that project this week! :-/

thanks!

here the code:

Code: [Select]
// 7 pushbuttons, any of them initiating a picture

//------------------ATTRIBUT --------------------------------
// Buttons
int buttonPin = 0;
int buttonPin2 = 2;
int buttonPin3 = 3;
int buttonPin4 = 4;
int buttonPin5 = 5;
int buttonPin6 = 6;
int buttonPin7 = 7;
int buttonPin8 = 8;

// which apparat?

//pictures
int pic2 =  2.jpeg;
int pic3 =  3.jpeg;
int pic4 =  4.jpeg;
int pic5 =  5.jpeg;
int pic6 =  6.jpeg;
int pic7 =  7.jpeg;
int pic8 =  8.jpeg;

// Variable?
int buttonState = 0;
     
// --------------Method to read the buttons--------
 void setup() {
 pinMode(buttonPin2, INPUT);
 pinMode(buttonPin3, INPUT);
 pinMode(buttonPin4, INPUT);
 pinMode(buttonPin5, INPUT);
 pinMode(buttonPin6, INPUT);
 pinMode(buttonPin7, INPUT);
 pinMode(buttonPin8, INPUT);
 
 pinMode(pic2, OUTPUT);
 pinMode(pic3, OUTPUT);
 pinMode(pic4, OUTPUT);
 pinMode(pic5, OUTPUT);
 pinMode(pic6, OUTPUT);
 pinMode(pic7, OUTPUT);
 pinMode(pic8, OUTPUT);

 //serial.write,OUTPUT;
}

void loop() {
 // what method for digitalRead?
  int reading = digitalRead(buttonPin);
  buttonState = digitalRead(buttonPin);

// says what arduino hace to do, if you are pushing button2
// better Try {....}  catch {...}?
// or case0 {...}, case 1...

if (buttonState "buttonPin2" == HIGH) {
 // method to et the image appear, eg:
 pic2= loadImage ("img/2.jpg");
}
 // or: Serial.println("img/2.jpg");  ?

 // or: JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   
           File datei = new File( "2.jpeg" );
           BufferedImage bild = ImageIO.read(2.jpeg);
   
           // Bild anzeigen
           JLabel label = new JLabel(new ImageIcon(bild));
           frame.getContentPane().add(label);
           
           frame.pack();
           frame.setVisible(true);

else if (buttonState buttonPin2 == LOW) default;
 // default ending the process, if button no longer is pressed

else if (buttonState buttonPin3 == HIGH)
..
..
..
..

else (buttonState buttonPin8 == LOW) default
}

}

hope thats not completly rubbish and it more or less easy to solve... :-/

thanks for commenting!
lkjh :)

robtillaart


first modify your post, select the code part and press the # button so it looks better...

You are mixing up different programming languages ..

The Arduino part is quite straightforward:

(code not compiled or tested)
Code: [Select]

#define BUTTONS 7

int buttons[BUTTONS] = {2,3,4,5,6,7,8};
       
void setup()
{
  Serial.begin(115200);  // PC should match thos speed
  Serial.println("-- start -- ");
  for (int i=0; i< BUTTONS; i++) pinMode(buttons[i], INPUT);
}

void loop()
{
  for (int i=0; i< BUTTONS; i++) if (digitalRead(buttons[i]) == HIGH) Serial.println(i, DEC);
  delay(100);
}


Now you have to write code in your fav prog lang to capture the output from the Arduino and display the picture.

Please post your final code when ready.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

lkjh

thank you very much robtillaart, the code works better than mine...
doesnt has any errors in arduino.

but i dont understand why you now used a void loop?

is there no way to write a code which makes that, what i wrote earlier?
push one of the buttons - the dedicated pictures comes up, dont press the button anymore - picture disappears.

still dont know how to define the pictures and how to command them.

do  i dont have to convert them?

im studying art not informatics, so already that
"Now you have to write code in your fav prog lang to capture the output from the Arduino and display the picture."
i dont know what to do.

need an explanation step by step...
thanks!!!!

PaulS

Quote
still dont know how to define the pictures and how to command them.

Hold up your Arduino. Do you see a place on it to display a picture? I didn't think so.

What you CAN do is send a message to the PC telling it to display a picture. Send the appropriate message when a switch is pressed. Send another when the switch is released.

Then, write an application on the PC that reads those messages, and displays the appropriate picture on the PC screen.

lkjh

oh thanks, havent seen before that arduino hasnt a display..
but thats exactly i asked for the whole time, how to tell the pc do it...

next try:

now im using python to let the pictures appear and im writing the code in komodo.

Code: [Select]

def (btn_i):    # picture to show when button pushed
     ....1, DEC = btn_1
     ...?
       
import serial

ser = serial.Serial('/dev/ttyUSB0', 9600)

var = 1
while var == 1:
    if ser.inWaiting() > 0:
    if ser.readline == "btn_2":
    form.show_form(placement, bordertype, name)
    //to Show the image?
    if.....
    form.hide_form(.....)
    //is it possible to hide the image. or is it already included in the arduino code?
   
    elif ser.readline == "btn_3":
    print-3.jpeg //better just use print?
   
    elif ser.readline == "btn_4":
    print-4.jpeg
   
    elif ser.readline == "btn_5":
    print-5.jpeg
   
    elif ser.readline == "btn_6":
    print-6.jpeg
   
    elif ser.readline == "btn_7":
    print-7.jpeg
   
    elif ser.readline == "btn_8":
    print-8.jpeg

robtillaart

#5
Jun 13, 2011, 09:56 pm Last Edit: Jun 13, 2011, 09:58 pm by robtillaart Reason: 1
first write a small program just to see what you will get from the Arduino... SO you are sure that part is semantically correct  (it outputs a different message for every button)

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Christian Møhring Madsen

My best quess is Processing (http://www.arduino.cc/playground/Interfacing/Processing), i havent been tinkering with it yet, but i think this would be the easyest.

Msquare

"This week" ...  :smiley-eek:  :smiley-surprise:

I've used the Processing and it looks superficially the same as the Arduino, BUT but but, the Arduino is C (or C++) and the Processing is Java (a subset, as it runs "under" the Java doing all the fancy display). So keep those two apart (even though they both use ".pde" as the file extension)

That important bit, you must use Serial class in Processing, and then you can write single bytes/strings to the Arduino and/or read single bytes from it. The Arduino must do the same - ie Recieve/Send.

You can look at an old post of mine here (where I actually have a problem, but it probably does not apply to you) but it has a nice simple pair of Processing/Arduino programs that send messages both ways. Edit and adapt.

Go Up