Shop OBEX P1 Docs P2 Docs Learn Events
new project need help — Parallax Forums

new project need help

science_geekscience_geek Posts: 247
edited 2007-06-13 14:07 in Robotics
im am going to get the piezo film tabs from the parallax website in a few days and i need help with some minor coding, i want to make a guitar so that when i hit the tab and a switch a certain frequency plays, but i want the switches to be worth a·certain value like switch one = 200 and the 200 would be added to the frequency of the tab that is hit, a sample code could be

'IN1 = PIEZO TAB
'IN4 = FREQUENCY ADDER
ADDER····· PIN···· 4
ADDER1 = 200
IF IN1 = 1 AND ADDER = 1 THEN
FREQOUT 15, 10, (1000 + ADDER1)



dont think you guys will quite understand this, but i know somebody out there speaks my language

Comments

  • UncandayUncanday Posts: 28
    edited 2007-06-11 17:43
    If I understand what you're trying to do, you want several tabs (which will be detected on different input pins) and you want to output a single frequency, the value of which is dependent on all the tabs pressed?

    Something like, if, say, tab 1 is worth 200, tab 2 is worth 400 and tab 3 is worth 800, so the output is 1200 if 2 and 3 are pressed at the same time, and 600 if 1 and 2 are pressed at the same time?

    Regards
    Duncan
  • science_geekscience_geek Posts: 247
    edited 2007-06-12 01:03
    thats exactly what i mean, but how do i do it
  • UncandayUncanday Posts: 28
    edited 2007-06-12 04:39
    ok. Something like this?

    
    ACCUMULATE = 1000
    
    IF IN1=1 THEN
      ACCUMULATE = ACCUMULATE + 200
    ENDIF
    IF IN2=1 THEN
      ACCUMULATE = ACCUMULATE + 400
    ENDIF
    IF IN3=1 THEN
      ACCUMULATE = ACCUMULATE + 800
    ENDIF
    FREQOUT 15, 10, ACCUMULATE
    
    
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-06-12 05:14
    The INS statement is a useful way to collect the states of mutiple pins in one go, for example if pins 0-3 are to be used as switches their inputs can be read as a binary number and stored in a variable

    switches VAR NIB

    switches=INA

    SELECT switches

    CASE 1

    frequency 1

    CASE 2

    frequency 2

    etc.

    Jeff T.
  • science_geekscience_geek Posts: 247
    edited 2007-06-12 17:16
    one last question regarding what uncanday last posted, wouldnt the speaker always be play the frequency of 1000 even if the buttons werent pressed, so wouldnt accumulator = 0 and the if then would be if piezo hit then accumulator = 1000 + in1
  • GadgetmanGadgetman Posts: 2,436
    edited 2007-06-13 13:12
    How many tabs are you using, and is the frequencies direct multiples of each other?

    Consider placing the tabs on adjacent I/O pins, and reading them all together.

    If the frequencies are multiples (200/400/800/1600/3200) take the value that you read from the port, and just multiply it with the lowest frequency. (If you have a 'base frequency' of say 1000, just add it afterwards)

    If they're NOT multiples, write a table with every combination, and use the value read from the port as a pointer...
    (takes a bit of space, but is much faster and 'cleaner' code. Also, and 'base frequency' can be incorporated to the table. )

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
  • science_geekscience_geek Posts: 247
    edited 2007-06-13 14:07
    i plan on doing the last thing you said, and im using 5 tabs, i figure i'll make it as guitary possible
Sign In or Register to comment.