マトリックスLEDとアナログジョイスティックを連携!

モジュールをそれぞれアルディーノにつないで

アナログリードした値を整えてXY座標に代入します。

 

#include "LedControl.h"

LedControl lc=LedControl(12,10,11,1);

/* we always wait a bit between updates of the display */
unsigned long delaytime1=500;
unsigned long delaytime2=50;
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output

void setup() {
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,8);
  /* and clear the display */
  lc.clearDisplay(0);
  
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  Serial.begin(9600);
}

void loop() { 
 int a =analogRead(X_pin);
  float b = ((float)a/1023)*8;
  int int_x =(int)b;
   int c =analogRead(Y_pin);
  float d = ((float)c/1023)*8;
  int int_y =(int)d;
 
   lc.setLed(0,int_y,int_x,true);  
   delay(300);
    lc.setLed(0,int_y,int_x,false);  
 }