Hola,

Este es el programa programa básico "Hello World" para Wiring y OSC.
También adjunto un Patch de Pd para leer datos de los sensores. 

//------------------------------------------------------
//------------------------------------------------------
//   
//  AVRLIB-DEMO
//  For avrlib and Wiring development board.
//  
//
//  File:     sensosc.c
//  Author:   Juan Reyes    juanig-at-ccrma-stanford_edu
//            based on Michael Gurevich and Wendy Ju demo
//  Date:     July 1, 2008
//
//  Notes:
//-----------------------------------------------------
//  USING THE WIRING DEVELOPMENT BOARD, ANALOG INPUTS 
//  PORTF IN ATMEGA128 TO SEND SENSOR DATA USING OSC
//
//-----------------------------------------------------
//  Layout of ports in Wiring board correspond with
//  ATMega128 as follows:
//
//  ATMega128                WIRING
//  =========                ======
//  
//  PORTD                    PORT-0
//  PORTC                    PORT-1
//  PORTF                    ANALOG IN
//  PORTG                    BUILT-IN LED
//-----------------------------------------------------
//  Layout of analog pins in Wiring board correspond with
//  ATMega128 as follows:
//
//  Ch0                   W-APIN0
//  Ch1                   W-APIN1
//   .                      .
//  Ch7                   W-APIN7
//
//   Function a2dConvert10bit(Ch) reads and converts analog
//   values.
//
//-----------------------------------------------------
//  More information about Wiring board:
//
//  http://wiring.org.co/hardware/index.html
//  
//-----------------------------------------------------
//  Information about functions used here and avrlib:
// 
//  ~/avrlib/examples/a2d/a2dtest.c
//  ~/avrlib/ccrma/osc.c
//

//  
//*********************************************************
//   Description:
//   ============
//
//   This program will send sensor data values using OSC.
//   Sensors are connected to analog in (0) and (1) on 
//   Wiring board. For example you can try a photoresistor 
//   and a POT, one to control Frequencies and the other to
//   control amplitude (volume). 
//
//   Use with Pd can be seen on the accompanying patches.
//   Make sure you have OSC library and SerialIO objects in Pd. 
//
//   Information about analog sensors and Wiring:
//   http://wiring.org.co/learning/examples/photoresistor.html
//
//   Information about OSC:
//   http://opensoundcontrol.org/introduction-osc
//
//*********************************************************


#include <avr/io.h>
#include <avr/pgmspace.h>

#include "global.h"
#include "uart.h"
#include "ccrma/osc.h"
#include "timer128.h"    // use timer128.h for ATMega128
#include "a2d.h"

int main(void)
{
     u16 count;
     u16 a2dvalues[2];

     // Initialize libraries
     uartInit();
     oscInit();
     timerInit();

     // Set baud rate 115200 works on FTDI and Wiring
     uartSetBaudRate(115200);

     // ATOD STUFF
     a2dInit();
  
     // set PORTA pins to input (for ADC) 
     outb(DDRF, 0x00);        
     // turn pull-ups off 
     outb(PORTF, 0x00);   
     count = 0;          // counter variable
     
     while(1) {
       
       // Write OSC packet header, argument length = 4bytes
       oscSendMessageInt(PSTR("/counter"), count++);


       // Read sensor values and store in array a2dvalues[]
       a2dvalues[0] = a2dConvert10bit(0);
       a2dvalues[1] = a2dConvert10bit(1);

       // write OSC packet header, argument length = 8bytes
       oscSendMessageIntInt(PSTR("/a2dvalues"), a2dvalues[0],
a2dvalues[1]);
       
       // Here we send a bang every 100 iterations
       if (!(count % 100)) {
         oscSendMessageString(PSTR("/bbang"),"bang");
       }
       
       if (count > 2048) {
         count = 0;
       }
       timerPause(10);
     }

     return 0;
}




<<attachment: oscmeter-pd.png>>

_______________________________________________
____ ____ ___  ____ _  _ ___
|__| |__/   /  |___  \/  |__]
|  | |  \  /__ |___ _/\_ |

Arzexp mailing list
[email protected]
http://lists.slow.tk/listinfo.cgi/arzexp-slow.tk

Responder a