ATTiny85 8 TEST — Cardputer Adv simulation

An interactive Cardputer Adv circuit simulation you can run free in your browser on Velxio, by ian7171.

Components

Sketch code

#include <M5Cardputer.h>

#define DATA_PIN  13
#define CLOCK_PIN 14

int previousClock = LOW;

uint8_t receivedByte = 0;
uint8_t bitCount = 0;

void setup()
{
    auto cfg = M5.config();
    M5Cardputer.begin(cfg, true);

    pinMode(DATA_PIN, INPUT);
    pinMode(CLOCK_PIN, INPUT);

    M5Cardputer.Display.setRotation(1);
    M5Cardputer.Display.setTextSize(2);
    M5Cardputer.Display.setCursor(0, 0);

    M5Cardputer.Display.println("ATtiny85:");
}

void loop()
{
    int clock = digitalRead(CLOCK_PIN);

    /*
     * Rising clock edge
     */
    if (clock == HIGH && previousClock == LOW)
    {
        int bit = digitalRead(DATA_PIN);

        receivedByte <<= 1;

        if (bit)
            receivedByte |= 1;

        bitCount++;

        /*
         * Eight bits = one character
         */
        if (bitCount == 8)
        {
            M5Cardputer.Display.print((char)receivedByte);

            receivedByte = 0;
            bitCount = 0;
        }
    }

    previousClock = clock;

}

More projects by ian7171