Pages: [1]   Go Down
Author Topic: pushing a button makes appear a picture at the computerscreen  (Read 2049 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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 smiley
« Last Edit: June 13, 2011, 06:25:01 am by lkjh » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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:
#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.
Logged

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!!!!
 
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)

« Last Edit: June 13, 2011, 02:58:36 pm by robtillaart » Logged

Rob Tillaart

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

Denmark
Offline Offline
Newbie
*
Karma: 0
Posts: 19
King of Greenland
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1206
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"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.
Logged

Pages: [1]   Go Up
Jump to: