Maurin Donneaud

Designer d’interaction @ DataPaulette, Hackerspace textile, 19 rue Garibaldi 93100 Montreuil (Seine-Saint-Denis).

T201/Arduino/firmware

  1. // XYinteraction pour EDF
  2. int ledPin[] = {
  3.   99, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2 };
  4. int DEL = 50;
  5. int ledVal;
  6. int rowVal = 0;
  7. int val = 0;
  8. int minVal = 90; // ne bouge pas si allim 12 Volts
  9. int maxVal = 1024;
  10. int oldval;
  11. boolean DEBUG = true;
  12. void setup(){
  13.   if(DEBUG)Serial.begin(19200);      // connect to the serial port
  14.   if(DEBUG) Serial.println("START");
  15.   for(int i=1; i<=10; i++){
  16.     pinMode(ledPin[i], OUTPUT);      // sets the digital pin as output
  17.   }
  18.   for(int i=1; i<=10; i++){
  19.     digitalWrite(ledPin[i], HIGH);   // sets the LED on
  20.     delay(80);
  21.   }
  22.   for(int i=10; i>=1; i--){
  23.     digitalWrite(ledPin[i], LOW);    // sets the LED on
  24.     delay(80);
  25.   }
  26. }
  27. void loop(){
  28.  
  29.   rowVal = analogRead(1);
  30.   maxVal = analogRead(0);
  31.  
  32.   val = map(rowVal, minVal, maxVal, 0, 10); // 0 toutes les LEDs off
  33.   val = constrain(val, 0, 10);
  34.   if (val != 0) {
  35.     for(int i=1; i<=val; i++){
  36.       digitalWrite(ledPin[i], HIGH)  ;        // sets the LED on
  37.     }
  38.     if (val < 10){
  39.       for(int i=val+1; i<=10; i++){
  40.         digitalWrite(ledPin[i], LOW);       // sets the LED off
  41.       }
  42.     }
  43.   }
  44.   else {
  45.     for(int i=1; i<=10; i++){
  46.       digitalWrite(ledPin[i], LOW);         // sets the LED off
  47.     }
  48.   }
  49.   if(DEBUG){
  50.     // if(oldval != val){
  51.     //   oldval=val;
  52.     Serial.print(maxVal, DEC), Serial.print("\t");
  53.     Serial.print(rowVal, DEC), Serial.print("\t");
  54.     Serial.println(val, DEC);
  55.     delay(DEL);
  56.     // }
  57.   }
  58. }

T201/Arduino/Pachube/firmware

  1. /*
  2. Pachube Data Out
  3.  
  4.  Demonstrates use of the ERxPachube library.
  5.  Push local sensor data to Pachube server.
  6.  If you don't have a Pachube account, register one first (http://www.pachube.com/).
  7.  
  8.  To run this sketch, you need:
  9.  1. Create a same feed as http://www.pachube.com/feeds/26318
  10.  (A manual feed with three data streams with ids 0, 1, 2.)
  11.  2. Use your API key to replace the space holer PACHUBE_API_KEY below.
  12.  3. Use your feed id to replace the space holer PACHUBE_FEED_ID below.
  13.  
  14.  Circuit:
  15.  * Ethernet shield attached to pins 10, 11, 12, 13
  16.  
  17.  * Created 22 April 2011
  18.  * By Jeffrey Sun
  19.  * http://code.google.com/p/pachubelibrary/
  20.  
  21.  */
  22. #include <SPI.h>
  23. #include <Ethernet.h>
  24. #include "ERxPachube.h"
  25. #define PACHUBE_API_KEY  "XXXXXXXXXXXXXXXXXXXXXXX"
  26. #define PACHUBE_FEED_ID  "26318"
  27. // assign a MAC address for the ethernet controller.
  28. // Enter a MAC address and IP address for your controller below.
  29. // The IP address will be dependent on your local network.
  30. byte mac[] = { X, X, X, X, X, X };  // MAC address
  31. byte ip[] = { X, X, X, X };       // no DHCP so we set our own IP address
  32. byte server[] = { 209, 85, 146, 147 }; // www.pachube.com
  33. byte gateway[] = { 192, 168, X, X }; // the router's gateway address
  34. byte subnet[] = { 255, 255, 255, 0 };  // the subnet
  35. Client client(server, 80);             // initialize the library instance
  36. ERxPachubeDataOut dataout(PACHUBE_API_KEY, PACHUBE_FEED_ID);
  37. void PrintDataStream(const ERxPachube & pachube);
  38. void PrintString(const String & message) ;
  39. void setup(){
  40.   Serial.begin(9600);
  41.   Ethernet.begin(mac, ip, gateway, subnet);
  42.   dataout.addData("0");
  43. }
  44. void loop(){
  45.   Serial.println("+++++++++++++++++++++");
  46.   dataout.updateData("0", analogRead(0));
  47.   int status = dataout.updatePachube();
  48.   Serial.print("sync status code == "), Serial.println(status);
  49.   PrintDataStream(dataout);
  50.   delay(10000);
  51. }
  52. void PrintDataStream(const ERxPachube & pachube){
  53.   unsigned int count = pachube.countDatastreams();
  54.   Serial.print("data count=> ");
  55.   Serial.println(count);
  56.   Serial.println("<id>,<value>");
  57.   for(unsigned int i=0; i<count; i++){
  58.     PrintString(pachube.getIdByIndex(i));
  59.     Serial.print(",");
  60.     PrintString(pachube.getValueByIndex(i));
  61.     Serial.println();
  62.   }
  63. }
  64. void PrintString(const String & message){
  65.   String tmpStr = message;
  66.   int bufferSize = tmpStr.length() + 1;
  67.   char pBuffer[bufferSize];
  68.   tmpStr.toCharArray(pBuffer, bufferSize);
  69.   Serial.print(pBuffer);
  70. }

Forum sur abonnement

Pour participer à ce forum, vous devez vous enregistrer au préalable. Merci d'indiquer ci-dessous l'identifiant personnel qui vous a été fourni. Si vous n'êtes pas enregistré, vous devez vous inscrire.

Connexions'inscriremot de passe oublié ?