Skip to content

Commit

Permalink
Update structure to fit Swift 5.9 (#18)
Browse files Browse the repository at this point in the history
* Update structure to fit Swift 5.9

Signed-off-by: Andy Liu <andy@madmachine.io>

* Add import dependency

Signed-off-by: Andy Liu <andy@madmachine.io>

---------

Signed-off-by: Andy Liu <andy@madmachine.io>
  • Loading branch information
andy0808 authored Sep 8, 2023
1 parent 89ced6f commit 421a06c
Show file tree
Hide file tree
Showing 243 changed files with 1,784 additions and 2,607 deletions.
3 changes: 1 addition & 2 deletions Examples/SwiftIOPlayground/01LED/LEDBlink/.gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
14 changes: 7 additions & 7 deletions Examples/SwiftIOPlayground/01LED/LEDBlink/Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// swift-tools-version:5.7
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "LEDBlink",
dependencies: [
Expand All @@ -9,16 +11,14 @@ let package = Package(
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "LEDBlink",
dependencies: [
"SwiftIO",
"MadBoards"
"MadBoards",
]),
.testTarget(
name: "LEDBlinkTests",
dependencies: ["LEDBlink"]),
]
)

3 changes: 0 additions & 3 deletions Examples/SwiftIOPlayground/01LED/LEDBlink/README.md

This file was deleted.

This file was deleted.

18 changes: 18 additions & 0 deletions Examples/SwiftIOPlayground/01LED/LEDBlink/Sources/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// First import the SwiftIO and MadBoard libraries into the project to use related functionalities.
import SwiftIO
import MadBoard

// Initialize the specified pin used for digital output.
let led = DigitalOut(Id.D18)

// The code in the loop will run over and over again.
while true {
//Output high voltage to turn on the LED.
led.write(true)
// Keep the LED on for 1 second.
sleep(ms: 1000)

// Turn off the LED and then keep that state for 1s.
led.write(false)
sleep(ms: 1000)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
13 changes: 6 additions & 7 deletions Examples/SwiftIOPlayground/01LED/LEDBlinkWithTimer/Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// swift-tools-version:5.7
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "LEDBlinkWithTimer",
dependencies: [
Expand All @@ -9,16 +11,13 @@ let package = Package(
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "LEDBlinkWithTimer",
dependencies: [
"SwiftIO",
"MadBoards"
"MadBoards",
]),
.testTarget(
name: "LEDBlinkWithTimerTests",
dependencies: ["LEDBlinkWithTimer"]),
]
)
3 changes: 0 additions & 3 deletions Examples/SwiftIOPlayground/01LED/LEDBlinkWithTimer/README.md

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Import the SwiftIO library to control input and output and the MadBoard to use the id of the pins.
import SwiftIO
import MadBoard

// Initialize a digital pin for LED module.
let redLed = DigitalOut(Id.D18)

// Initialize the onboard blue LED.
let blueLed = DigitalOut(Id.BLUE)

// Initialize a timer for 1500ms.
let timer = Timer(period: 1500)

// Define a new function used to toggle the LED.
func ToggleLEDSwitch() {
redLed.toggle()
}

// Set an interrupt to reverse the LED state every time the interrupt occurs.
timer.setInterrupt(ToggleLEDSwitch)

// Blink onboard blue LED.
while true {
blueLed.high()
sleep(ms: 500)

blueLed.low()
sleep(ms: 500)
}

This file was deleted.

3 changes: 1 addition & 2 deletions Examples/SwiftIOPlayground/01LED/LEDMorseCode/.gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
13 changes: 6 additions & 7 deletions Examples/SwiftIOPlayground/01LED/LEDMorseCode/Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// swift-tools-version:5.7
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "LEDMorseCode",
dependencies: [
Expand All @@ -9,16 +11,13 @@ let package = Package(
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "LEDMorseCode",
dependencies: [
"SwiftIO",
"MadBoards"
"MadBoards",
]),
.testTarget(
name: "LEDMorseCodeTests",
dependencies: ["LEDMorseCode"]),
]
)
3 changes: 0 additions & 3 deletions Examples/SwiftIOPlayground/01LED/LEDMorseCode/README.md

This file was deleted.

This file was deleted.

41 changes: 41 additions & 0 deletions Examples/SwiftIOPlayground/01LED/LEDMorseCode/Sources/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Import the libraries to use all their functionalities.
import SwiftIO
import MadBoard

// Initialize the digital output pin.
let led = DigitalOut(Id.D18)

// Define the LED states to represent the letter s and o.
let sSignal = [false, false, false]
let oSignal = [true, true ,true]

// Set the LED blink rate according to the values in the array.
func send(_ values: [Bool], to light: DigitalOut) {
// The duration of slow flash and quick flash.
let long = 1000
let short = 500

// Iterate all the values in the array.
// If the value is true, the LED will be on for 1s, which is a slow flash.
// And if it’s false, the LED will be on for 0.5s, which is a quick flash.
for value in values {
light.high()
if value {
sleep(ms: long)
} else {
sleep(ms: short)
}
light.low()
sleep(ms: short)
}
}

// Blink the LED.
// At first, the LED starts 3 fast blink to represent s, then 3 slow blink to represent o, and 3 fast blink again.
// Wait 1s before repeating again.
while true {
send(sSignal, to: led)
send(oSignal, to: led)
send(sSignal, to: led)
sleep(ms: 1000)
}

This file was deleted.

3 changes: 1 addition & 2 deletions Examples/SwiftIOPlayground/01LED/RGBLED/.gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Loading

0 comments on commit 421a06c

Please sign in to comment.