Solving Approach

How do you plan to solve it?

 

 

Code

#include <SPI.h>

#define CS 10
#define COPI 11
#define CIPO 12
#define SCK 13
#define but 2

void setup() {
  // put your setup code here, to run once:
  pinMode(CS,OUTPUT);
  pinMode(COPI,OUTPUT);
  pinMode(CIPO, INPUT_PULLUP);
  pinMode(SCK,OUTPUT);
  pinMode(but,INPUT_PULLUP);

  SPI.begin();
  SPI.beginTransaction(SPISettings(2000000,MSBFIRST,SPI_MODE2));

  Serial.begin(115200);
  digitalWrite(CS,HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(but) == 0){
    digitalWrite(CS,LOW);
    uint8_t data = SPI.transfer(0x00);
    digitalWrite(CS,HIGH);
    Serial.println("You Rolled a " + String(data));
    delay(1000);
  }
}

 

Output

Photo of Output

Screenshot of Serial Terminal 

 

Upvote
Downvote

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!